简体   繁体   中英

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM