Walkthrough: Using XSLT IntelliSense
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
This walkthrough demonstrates how to use XSLT IntelliSense to auto-complete value of some attributes.
To use IntelliSense in the name attribute of xsl:with-param and xsl:call-template elements
Create a new XSLT file and copy in the following code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- These 2 elements effectively assign $messages = resources/en.xml/<messages>, then $messages is used in the "localized-message" template. --> <xsl:param name="lang">en</xsl:param> <xsl:variable name="messages" select="document(concat('resources/', $lang, '.xml'))/messages"/> <xsl:template name="msg23" match="msg23"> </xsl:template> <xsl:template name="localized-message"> <xsl:param name="msgcode"/> <!-- Show message string. --> <xsl:message terminate="yes"> <xsl:value-of select="$messages/message[@name=$msgcode]"/> </xsl:message> </xsl:template> </xsl:stylesheet>
Insert your cursor after
<xsl:template name="msg23" match="msg23">
and press Enter. Then start typing the followingxsl:call-template
element:<xsl:call-template name="localized-message"> </xsl:call-template>
The list of template names appears in the
name=""
attribute of thexsl:call-template
element as you type.Insert your cursor after
<xsl:call-template name="localized-message">
and press Enter. Then start typing the followingxsl:with-param
element:<xsl:with-param name="msgcode">msg23</xsl:with-param>
The list of parameter names appears in the
name=""
attribute of thexsl:with-param
element.
To use IntelliSense in the mode attribute of an xsl:apply-templates element
Create a new XSLT file and copy in the following code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <HTML> <BODY> <TABLE> <xsl:apply-templates select="customers/customer"> <xsl:sort select="state"/> <xsl:sort select="name"/> </xsl:apply-templates> </TABLE> </BODY> </HTML> </xsl:template> <xsl:template match="customer"> <TR> <xsl:apply-templates select="name" /> <xsl:apply-templates select="address" /> <xsl:apply-templates select="phone" /> </TR> </xsl:template> <xsl:template match="name"> <TD STYLE="font-size:14pt font-family:serif"> <xsl:apply-templates /> </TD> </xsl:template> <xsl:template match="address"> <TD> <xsl:apply-templates /> </TD> </xsl:template> <xsl:template match="phone"> <TD> <xsl:apply-templates /> </TD> </xsl:template> <xsl:template match="phone" mode="accountNumber"> <xsl:param name="Area_Code"/> <TD STYLE="font-style:italic"> 1-<xsl:value-of select="."/>-001 </TD> </xsl:template> </xsl:stylesheet>
Insert your cursor after
<xsl:apply-templates select="phone" />
and press Enter. Then start typing the followingxsl: apply-templates
element:<xsl:apply-templates select="phone" mode="accountNumber">
The list of template modes appears in the
mode=""
attribute of thexsl:apply-templates
element.
To use IntelliSense in the stylesheet-prefix and result-prefix attributes of an xsl:namespace-alias element
Create a new XSLT file and copy in the following code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:alt="http://www.w3.org/1999/XSL/Transform-alternate" version="1.0"> <xsl:param name="browser" select="'InternetExplorer'"/> <xsl:template match="/"> <alt:stylesheet> <xsl:choose> <xsl:when test="$browser='InternetExplorer'"> <alt:import href="IERoutines.xsl"/> <alt:template match="/"> <div> <alt:call-template name="showTable"/> </div> </alt:template> </xsl:when> <xsl:otherwise> <alt:import href="OtherBrowserRoutines.xsl"/> <alt:template match="/"> <div> <alt:call-template name="showTable"/> </div> </alt:template> </xsl:otherwise> </xsl:choose> </alt:stylesheet> </xsl:template> </xsl:stylesheet>
Insert your cursor after
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:alt="http://www.w3.org/1999/XSL/Transform-alternate" version="1.0">
and press Enter. Then start typing the followingxsl:namespace-alias
element:<xsl:namespace-alias stylesheet-prefix="alt" result-prefix="xsl"/>
Notice how the list of prefixes appeared in the
stylesheet-prefix
andresult-prefix
attributes of thexsl:namespace-alias
element.