Subject: Re: [xsl] Next node outside of axis pattern From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 17 Jul 2009 18:34:06 -0400 |
If I had an XML like the following (snippet tried to cover off most scenarios):
<?xml version="1.0"?> <root> <a>This is some text</a> <s> <section> <toc>Heading 1</toc> <p>This is<endofpage num="1"/> a paragraph</p> <p>This is a paragraph</p> </section> <section> <toc>Heading 2</toc> <p>This is a paragraph</p> </section> <section> <p>This is a paragraph</p> <p>This<endofpage num="2"/> is a paragraph</p> <li> <p>This is a paragraph</p> <p>This is a paragraph</p> </li> </section> <section> <toc>Heading 3</toc> <p>This is a paragraph</p> </section> </s> <a>This<endofpage num="3"/> is some more text</a> <p>This is a paragraph</p> </root>
the <endofpage> element can appear anywhere within the document in an element that contains text. The issues is building a table of contents of the <toc> elements. For <toc>Heading 1</toc> no problem using descendant axis. However with Heading 2 and Heading 3 I can't figure out how to get the page number. I'm looking for something like:
<xsl:template match="toc"> <p><xsl:value-of select="."/> ......... <!-- next endofpage/@num goes here --></p> </xsl:template>
Any thoughts?
T:\ftemp>type tickner.xml <root> <a>This is some text</a> <s> <section> <toc>Heading 1</toc> <p>This is<endofpage num="1"/> a paragraph</p> <p>This is a paragraph</p> </section> <section> <toc>Heading 2</toc> <p>This is a paragraph</p> </section> <section> <p>This is a paragraph</p> <p>This<endofpage num="2"/> is a paragraph</p> <li> <p>This is a paragraph</p> <p>This is a paragraph</p> </li> </section> <section> <toc>Heading 3</toc> <p>This is a paragraph</p> </section> </s> <a>This<endofpage num="3"/> is some more text</a> <p>This is a paragraph</p> </root>
T:\ftemp>xslt tickner.xml tickner.xsl <?xml version="1.0" encoding="utf-8"?> <table-of-contents> <p>Heading 1...............1</p> <p>Heading 2...............2</p> <p>Heading 3...............3</p> </table-of-contents> T:\ftemp>type tickner.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/"> <table-of-contents> <xsl:apply-templates select="//toc"/> </table-of-contents> </xsl:template>
<xsl:template match="toc"> <p> <xsl:value-of select="."/> <xsl:text>...............</xsl:text> <xsl:value-of select="(..//endofpage | ../following::endofpage)[1]/@num"/> </p> </xsl:template>
-- XSLT/XSL-FO/XQuery hands-on training - Oakland, CA, USA 2009-08-03 Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18 Video overview: http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Next node outside of axis pat, Spencer Tickner | Thread | Re: [xsl] Next node outside of axis, Spencer Tickner |
[xsl] Next node outside of axis pat, Spencer Tickner | Date | Re: [xsl] Next node outside of axis, Spencer Tickner |
Month |