p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

xslt thread: iterating through child nodes.


Message #1 by "chanoch" <chanochw@w...> on Mon, 26 Jun 2000 18:18:21
> Look at the xml snippet below
> 
> <p>
>   some text right here
>   <a href="some.file">a hyperlink</a>
>   some more text
> </p>
> 
> I want to be able to process the hyper link while leaving it 
> where it is.
> So for example I want to output the first section of text, 
> then only output the file refered to by the hyperlink and then output the 
> second section of text.
> 
> The way I saw myself doing it is to iterate through all the 
> child nodes (including the children, if they are text call value-of and 
> if they are hyper links call value-off select="href")
> 
> How can I do this?

Exactly as you describe:

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

<xsl:template match="a">
<xsl:value-of select="@href"/>
</xsl:template>

<xsl:template match="text()"> <!-- not really needed, it's the default
behaviour -->
<xsl:value-of select="."/>
</xsl:template>

Mike Kay

  Return to Index