raterus
raterus

Reputation: 2089

XSLT for-each, iterating through text and nodes

I'm still learning XSLT, and have a question about the for-each loop.

Here's what I have as far as XML

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

What I'd like is if the for-each loop iterate through these chunks 1. Here is a great URL 2. http://www.somesite.com 3. Some More Text

This might be simple, or impossible, but if anyone can help me out I'd appreciate it!

Thanks, Michael

Upvotes: 0

Views: 141

Answers (1)

JLRishe
JLRishe

Reputation: 101730

You should be able to do so with something like the following:

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

or this may be preferable because it allows you to have a single template that you can invoke from multiple different places:

<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>

Upvotes: 1

Related Questions