2013-03-18 125 views
0

我仍然在学习XSLT,并且有关于for-each循环的问题。XSLT for each,遍历文本和节点

这里就是我有尽可能XML

<body>Here is a great URL<link>http://www.somesite.com</link>Some More Text</body> 

我想是,如果换每个通过这些块 1.这里循环迭代是一个伟大的URL 2. http://www.somesite.com 3。一些更多文字

这可能很简单,或不可能,但如果任何人都可以帮助我,我会很感激!

感谢, 迈克尔

+0

您的预期输出是什么?请举个例子。 – Peter 2013-03-18 14:35:22

回答

1

您应该能够像下面这样做:

<xsl:for-each select=".//text()"> 
    <!-- . will have the value of each chunk of text. --> 
    <someText> 
    <xsl:value-of select="." /> 
    </someText> 
</xsl:for-each> 

或者这可能是可取的,因为它可以让你有,你可以调用一个模板来自多个不同的地方:

<xsl:apply-templates select=".//text()" mode="processText" /> 
<xsl:template match="text()" mode="processText"> 
    <!-- . will have the value of each chunk of text. --> 
    <someText> 
    <xsl:value-of select="." /> 
    </someText> 
</xsl:for-each>