2011-08-29 104 views
0

这里是我处理XML:我需要适应与第二结构为什么这个XSL模板无效?

<xsl:template match="/"> 
    <xsl:call-template name="CustomTemplate"/> 
</xsl:template> 

<xsl:template name="CustomTemplate"> 
    <xsl:template match="Row"> 
     <xsl:value-of select="@ID"/> 
    </xsl:template> 
</xsl:template> 

<dsQueryResponse> 
<Rows> 
<Row ID="14"></Row> 
</Rows> 
</dsQueryResponse> 

这XSL工作:

<xsl:template match="Row"> 
     <xsl:value-of select="@ID"/> 
    </xsl:template> 

但没有这一项,制作一个调用模板,有没有人知道第二个XSL中需要改变什么?

+1

XSL模板不能嵌套。请编辑你的文章,以显示你想输出给定的输入XML。 –

回答

0

我不认为你可以像这样嵌套模板。您可以执行的操作如下:

<xsl:template match="/"> 
    <xsl:call-template name="CustomTemplate"/> 
</xsl:template> 

<xsl:template name="CustomTemplate" match="Row"> 
    <!-- format rows here --> 
</xsl:template> 
+0

我也试过了,它也不行! – Holden

+0

@Holden - 它不工作的原因是因为上下文是'/',并且您试图访问'/ dsQueryResponse/Rows/Row'中的属性。你可以使用''。还要注意'match =“Row”'现在没有做任何事情。你可以完全删除这个匹配,它仍然可以工作。 –