Re: Checking on the existence of tail text?
I have a question about the check on a node tail text.
I'm suspecting a "proper" solution would have to look at all of your headings at a higher level, rather than at an individual template for sibling headings of different types. Typically when going from a flat vocabulary (like XHTML) to a hierarchical vocabulary (like DocBook), it is more appropriate to use XSLT 2 grouping using group-starting-with=.
But I'll still answer the questions you ask, they just might be the wrong questions.
How can de matching template of <h2> see if there is nont-whitespace text between </h1> and <h2>, e.g. the difference between
But I don't recommend that below, that just answers your question.
And the extended question, how van the h2-matching template see the same thing when there is another tag inbetween that get ignored in the output:
Here is where it gets tricky, because you need to limit the search back. And I'm not sure precisely what you are asking for: that the immediately preceding node isn't a white-space-only text node, or *any* node up until the closest <h1>.
I can only really guess what you want below.
This information is needed to know that white space to generate in output for PDF, where the combination of different heading must generate different amounts of leading.
Then I think the answer is done at a higher level looking at the combinations, rather than looking from each individual match.
The example below might help you, but it might not ... I hope it does. When you read the instruction name "<xsl:for-each-group>" say to yourself "for the first member of each group". I find this helps me and my students quickly understand what is going on in the loop.
. . . . . . . . . Ken
<h1>Abcd</h1> a text here <h2>Xyz</h2>some h2 here
<h1>Abcd</h1><!-- no text here --><h2>Xyz</h2>some h2 here
<h1>Abcd</h1> a text here<ignored/> another text here <h2>Xyz</h2>some h2 here
<h1>Abcd</h1><!-- no text here --><ignored/><!-- no text here --><h2>Xyz</h2>some h2 here
T:\ftemp>call xslt2 petr.xml petr.xsl
<?xml version="1.0" encoding="UTF-8"?>
Test 1: <!--Got some non-white-space text before h2--> <!--Here's an H2-->
<xsl:template match="body"> Test <xsl:number/>: <xsl:for-each-group select="node()" group-starting-with="h1"> <!--split body into all of the h1 groups--> <xsl:if test="self::h1"> <!--looking at all of the nodes including and after an h1--> <xsl:for-each-group select="current-group()[position()>1]" group-starting-with="h2"> <!--analyze each h1 group looking for h2--> <xsl:choose> <xsl:when test="self::h2"> <xsl:comment>Here's an H2</xsl:comment> <xsl:text>
</xsl:text> </xsl:when> <xsl:when test="current-group()/self::text()[normalize-space()]"> <xsl:comment>Got some non-white-space text before h2</xsl:comment> <xsl:text>
</xsl:text> </xsl:when> <xsl:otherwise> <xsl:comment>Nothing of note before h2</xsl:comment> <xsl:text>
</xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:if> </xsl:for-each-group>
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format