print all subelements plus content

D

David Simons

Hi,

I don't know how to print out all subcontent of an
element with xslt. E.g.
<book>
<chapter>first chapter
<content>
lorem ipsum bla
</content>
</chapter>
<chapter>second chapter
<content>
that and this and this and that
</content>
</chapter>
.......
</book>

xslt:
.....
<xsl:for-each select="book"> <xsl:value-of select="child::*"/>
</xsl:for-each>
....

But this just gives me the first chapter but none of
the other chapters, I don't know why?

Regards,

David
 
W

Warrell Harries

Hi David,

I'm guessing that you are new to XSL. To get the most out of it
requires a change of mind-set and, in my opinion, this requires
avoiding use of <xsl:for-each> until you get your head around the
declarative basis of XSLT.

That aside, to answer your question, what you have done is set the
document context to the first book element and then selected the child
axis only for that first book element.

You would be better off defining a template :-

<xsl:template match="chapter">
<xsl:value-of select="content"/>
</xsl:template>

and then triggering this by using

<xsl:apply-templates select="book"/>

from wherever you want/need to.

I hope this helps - if you persevere it will pay the same sort of
dividends as a true understanding of SQL.

Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,245
Members
46,839
Latest member
MartinaBur

Latest Threads

Top