Sdílet prostřednictvím


Návod: Používání IntelliSense XSLT

Tento názorný postup ukazuje, jak pomocí technologie IntelliSense XSLT automaticky dokončit hodnotu některých atributů.

Použití IntelliSense v atributu názvu xsl:with-param a xsl:call-template elementy

  1. Vytvořte nový soubor XSLT a zkopírujte ho do následujícího kódu:

    <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>
    
  2. Vložte kurzor za <xsl:template name="msg23" match="msg23"> a stiskněte Enter. Pak začněte psát následující xsl:call-template prvek:

    <xsl:call-template name="localized-message">
    </xsl:call-template>
    

    Seznam názvů šablon se zobrazí v name="" atributu elementu xsl:call-template při psaní.

  3. Vložte kurzor za <xsl:call-template name="localized-message"> a stiskněte Enter. Pak začněte psát následující xsl:with-param prvek:

    <xsl:with-param name="msgcode">msg23</xsl:with-param>
    

    Seznam názvů parametrů se zobrazí v name="" atributu elementu xsl:with-param .

Použití IntelliSense v atributu režimu elementu xsl:apply-templates

  1. Vytvořte nový soubor XSLT a zkopírujte ho do následujícího kódu:

    <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>
    
  2. Vložte kurzor za <xsl:apply-templates select="phone" /> a stiskněte Enter. Pak začněte psát následující xsl: apply-templates prvek:

    <xsl:apply-templates select="phone"  mode="accountNumber">
    

    Seznam režimů šablon se zobrazí v mode="" atributu xsl:apply-templates prvku.

Použití IntelliSense v atributu stylesheet-prefix a result-prefix elementu xsl:namespace-alias

  1. Vytvořte nový soubor XSLT a zkopírujte ho do následujícího kódu:

    <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>
    
  2. Vložte kurzor za <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:alt="http://www.w3.org/1999/XSL/Transform-alternate" version="1.0"> a stiskněte Enter. Pak začněte psát následující xsl:namespace-alias prvek:

    <xsl:namespace-alias stylesheet-prefix="alt" result-prefix="xsl"/>
    

    Všimněte si, jak se seznam předpon objevil v elementu stylesheet-prefix a result-prefix atributy xsl:namespace-alias .