2013-10-30 96 views
0

如何在xslt中獲得具有某個特定姓名的另一個孩子的所有孩子?XSLT選擇特定孩子

例如:

<node> 
    <text> 
     <char></char> 
    </text> 
    <text> 
     <char></char> 
    </text> 
    <text> 
     <tag></tag> 
    </text> 
</node> 

我要打電話到應用模板具有tag內的所有text節點,並調用另一個模板中的所有文本節點,具有char

回答

1
<xsl:template match="node"> 
    <xsl:apply-templates select="text[tag]"/> 
    <xsl:call-template name="foo"> 
    <xsl:with-param name="elements" select="text[char]"/> 
    </xsl:call-template> 
</xsl:template> 

應該給你一個想法,雖然我會建議在兩種情況下使用apply-templates,使用不同的模式或合適的匹配模式:

<xsl:template match="node"> 
    <xsl:apply-templates/> 
</xsl:apply-templates> 

<xsl:template match="text[tag]"> 
    ... 
</xsl:templates> 

<xsl:template match="text[char]"> 
    ... 
</xsl:templates>