你可以在模板中调用模板吗?例如:
如果我想要使用
<xsl:choose>
  <xsl:when test="//*[local-name()='RetrieveCCTransRq']">
    <xsl:call-template name="SOAPOutput"/>
  </xsl:when>
</xsl:choose>
<xsl:template name="SOAPOutput">
  <SOAP-ENV:Envelope>
    <SOAP-ENV:Body>
      <OutputPayload>
        <TotalTransactions>
          <xsl:value-of select="count(//Transaction)"/>
        </TotalTransactions>
        <Transactions>
          <xsl:apply-templates/>
        </Transactions>
      </OutputPayload>
    </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>
  <xsl:template match="Transaction">
    <xsl:choose>
      <xsl:when test="contains(Type,'Debit')">
        <Debit>
          <xsl:apply-templates select="Date"/>
          <xsl:apply-templates select="PostDate"/>
          <xsl:apply-templates select="Description"/>
          <xsl:apply-templates select="Amount"/>
        </Debit>
      </xsl:when>
      <xsl:otherwise>
        <Credit>
          <xsl:apply-templates select="Date"/>
          <xsl:apply-templates select="PostDate"/>
          <xsl:apply-templates select="Description"/>
          <xsl:apply-templates select="Amount"/>
        </Credit>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="Date">
    <Date>
      <xsl:value-of select="."/>
    </Date>
  </xsl:template>
  <xsl:template match="PostDate">
    <PostDate>
      <xsl:value-of select="."/>
    </PostDate>
  </xsl:template>
  <xsl:template match="Description">
    <Description>
      <xsl:value-of select="."/>
    </Description>
  </xsl:template>
  <xsl:template match="Amount">
    <Amount>
      <xsl:value-of select="."/>
    </Amount>
  </xsl:template>
</xsl:template>
一个<xsl:template>指令只能在全局级别定义(必须的子<xsl:stylesheet>指令).
另一个建议是避免节点类型的条件测试.而不是这个:
Run Code Online (Sandbox Code Playgroud)<xsl:choose> <xsl:when test="//*[local-name()='RetrieveCCTransRq']"> <xsl:call-template name="SOAPOutput"/> </xsl:when> </xsl:choose>
建议使用这个:
<xsl:template match="RetrieveCCTransRq">
  <!-- Place the body of the named template here -->
</xsl:template>
通过这种方式,您不必编写上面引用的六行代码,您可以轻松地提交任何类型的错误.此外,您已将命名模板转换为匹配模板,获得更多灵活性和可重用性,并且您已经消除了一个程序(拉式)处理.懒惰和聪明 - 让XSLT处理器为你做节点类型检查 :)
| 归档时间: | 
 | 
| 查看次数: | 8155 次 | 
| 最近记录: |