Re: [xsl] Next node outside of axis pattern

Subject: Re: [xsl] Next node outside of axis pattern
From: Spencer Tickner <spencertickner@xxxxxxxxx>
Date: Fri, 17 Jul 2009 15:56:57 -0700
That worked great Ken. Unfortunately I can't do much about the page
elements as they need to be inline exactly where they appear in print
for the web for reference purposes.

Thanks again,

Spencer

On Fri, Jul 17, 2009 at 3:34 PM, G. Ken
Holman<gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
> At 2009-07-17 15:24 -0700, Spencer Tickner wrote:
>>
>> If I had an XML
>> like the following (snippet tried to cover off most scenarios):
>>
>> <?xml version="1.0"?>
>> <root>
>> B  B  B  B <a>This is some text</a>
>> B  B  B  B <s>
>> B  B  B  B  B  B  B  B <section>
>> B  B  B  B  B  B  B  B  B  B  B  B <toc>Heading 1</toc>
>> B  B  B  B  B  B  B  B  B  B  B  B <p>This is<endofpage num="1"/> a
paragraph</p>
>> B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
>> B  B  B  B  B  B  B  B </section>
>> B  B  B  B  B  B  B  B <section>
>> B  B  B  B  B  B  B  B  B  B  B  B <toc>Heading 2</toc>
>> B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
>> B  B  B  B  B  B  B  B </section>
>> B  B  B  B  B  B  B  B <section>
>> B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
>> B  B  B  B  B  B  B  B  B  B  B  B <p>This<endofpage num="2"/> is a
paragraph</p>
>> B  B  B  B  B  B  B  B  B  B  B  B <li>
>> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
>> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
>> B  B  B  B  B  B  B  B  B  B  B  B </li>
>> B  B  B  B  B  B  B  B </section>
>> B  B  B  B  B  B  B  B <section>
>> B  B  B  B  B  B  B  B  B  B  B  B <toc>Heading 3</toc>
>> B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
>> B  B  B  B  B  B  B  B </section>
>> B  B  B  B </s>
>> B  B  B  B <a>This<endofpage num="3"/> is some more text</a>
>> B  B  B  B <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?
>
> So by "next" do you need the "closest" <endofpage> element to the start of
> each given section with a <toc>?
>
> Since you are already in a section's child, that would entail going up to
> the parent of <toc> and down as well as those that follow, so the first of
> the union of those addressed elements:
>
> B (..//endofpage | ../following::endofpage)[1]
>
> ... though I would strongly suggest you revisit your XML to see if the
> <endofpage> can be more logically positioned. B I understand of course that
> many times we have to deal with what we are given, but it would seem to me
> there are too many opportunities for a misplaced <endofpage> element.
>
> I hope the example below helps.
>
> . . . . . . . . . . Ken
>
> T:\ftemp>type tickner.xml
> <root>
> B  B  B  B <a>This is some text</a>
> B  B  B  B <s>
> B  B  B  B  B  B  B  B <section>
> B  B  B  B  B  B  B  B  B  B  B  B <toc>Heading 1</toc>
> B  B  B  B  B  B  B  B  B  B  B  B <p>This is<endofpage num="1"/> a
paragraph</p>
> B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
> B  B  B  B  B  B  B  B </section>
> B  B  B  B  B  B  B  B <section>
> B  B  B  B  B  B  B  B  B  B  B  B <toc>Heading 2</toc>
> B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
> B  B  B  B  B  B  B  B </section>
> B  B  B  B  B  B  B  B <section>
> B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
> B  B  B  B  B  B  B  B  B  B  B  B <p>This<endofpage num="2"/> is a
paragraph</p>
> B  B  B  B  B  B  B  B  B  B  B  B <li>
> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
> B  B  B  B  B  B  B  B  B  B  B  B </li>
> B  B  B  B  B  B  B  B </section>
> B  B  B  B  B  B  B  B <section>
> B  B  B  B  B  B  B  B  B  B  B  B <toc>Heading 3</toc>
> B  B  B  B  B  B  B  B  B  B  B  B <p>This is a paragraph</p>
> B  B  B  B  B  B  B  B </section>
> B  B  B  B </s>
> B  B  B  B <a>This<endofpage num="3"/> is some more text</a>
> B  B  B  B <p>This is a paragraph</p>
> </root>
>
>
> T:\ftemp>xslt tickner.xml tickner.xsl
> <?xml version="1.0" encoding="utf-8"?>
> <table-of-contents>
> B  <p>Heading 1...............1</p>
> B  <p>Heading 2...............2</p>
> B  <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";
> B  B  B  B  B  B  B  B version="1.0">
>
> <xsl:output indent="yes"/>
>
> <xsl:template match="/">
> B <table-of-contents>
> B  B <xsl:apply-templates select="//toc"/>
> B </table-of-contents>
> </xsl:template>
>
> <xsl:template match="toc">
> B <p>
> B  B <xsl:value-of select="."/>
> B  B <xsl:text>...............</xsl:text>
> B  B <xsl:value-of select="(..//endofpage |
> ../following::endofpage)[1]/@num"/>
> B </p>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
> T:\ftemp>
>
>
> --
> XSLT/XSL-FO/XQuery hands-on training - Oakland, CA, USA 2009-08-03
> Crane Softwrights Ltd. B  B  B  B  B http://www.CraneSoftwrights.com/s/
> Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
> Video lesson: B  B http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
> Video overview: B http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
> G. Ken Holman B  B  B  B  B  B  B  B  mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
> Male Cancer Awareness Nov'07 B http://www.CraneSoftwrights.com/s/bc
> Legal business disclaimers: B http://www.CraneSoftwrights.com/legal

Current Thread