xslt中的第一个子节点名称

问题描述:

我想知道如何在xslt中找到特定节点的第一个子节点名称。xslt中的第一个子节点名称

我有一个xml:

<name> 
    <body> 
     <para> 
     <text> some text</text> 
     </para> 
    </body> 
    </name> 

可以用体/节点(i得名)[1] /本地名称()?

<xsl:template match="name"> 
<name> 
<xsl:variable name="firstchild" select="body/node()[1]/local-name()"> 
         </xsl:variable> 
<xsl:value-of select="$firstchild" /> 
</name> 
</xsl:template> 

输出应该

<name> 
    para 
    </name> 
+0

你试图显示哪个元素?你试图显示元素的名称,或元素的内容? – freefaller 2012-07-17 16:49:26

+0

只是一个名字... – atif 2012-07-17 16:53:06

尝试这样的事情...

<xsl:template match="name"> 
    <name> 
    <xsl:variable name="firstchild" select="name(body/*[1])"/> 
    <xsl:value-of select="$firstchild" /> 
    </name> 
</xsl:template> 

或者,如果你实际上并不需要的变量,只是单纯的......

<xsl:template match="name"> 
    <name> 
    <xsl:value-of select="name(body/*[1])" /> 
    </name> 
</xsl:template> 

这里是一个xmlplayground的t他第二个例子...看到<name>para</name>在输出窗口中点击View Source

+0

@Atif,不客气:-) Upvotes总是不错的;-) – freefaller 2012-07-17 17:09:45