Subject: Re: testing for position of an element and displaying it accordingly
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 19 Jan 2007 15:43:47 GMT
|
<xsl:if test child::a>
<xsl:apply-templates select="a" mode="test"/>
</xsl:if>
This seems to be the same problem as the "Axis specifers" list posted
earlier, as explained there, teh xsl:if is not doing anything, the above
three lines are equivalent to
<xsl:apply-templates select="a" mode="test"/>
and these have teh effect of processing all a elements, you don't want
to do that you want to process all elements in order, both a and b. so
just have
<xsl:template match="r1">
<xsl:apply-templates />
</xsl:template>
a elements appear to be paragraphs
<xsl:template match="a">
<p><xsl:apply-templates /></p>
</xsl:template>
and you want elements to be numbered
<xsl:template match="b">
<p><xsl:number/><xsl:apply-templates /></p>
</xsl:template>
this is again equivalent to the code posted in the earlier thread.
> How do I check that if there are <a> elements before
> <b> element inside <r1>, then they should be displayed
> before the <b> element. And if there are <a> elements
> after the <b> element, they should be displayed after
> the <b> element?
you could check with test="b/preceding-sibling::a" but there is no need
to check as the behaviour that you want is the defualt behaviour, the
only reason that the a and b elements are being processed out of order
is that elsewhere in your code you explictly select all the a elements
so they are being processed first.
David
|