|
Subject: RE: [xsl] Need test for preceding-sibling From: "Hintz, David L" <david.hintz@xxxxxxxxxxx> Date: Thu, 23 Apr 2009 16:23:27 -0400 |
Now I see that I over-simplified the problem. The XSLT also has to suppress
any <a1> that is not paired with an <a2>. So, I'm not sure the grouping works
in your example since there could be two <a1/> elements that are in the group
that ends with <a2/>. But, if you specify:
<xsl:for-each-group select="*"
group-starting-with="a1"
group-ending-with="a2">
will that consider "<a1/><a1/><a2/>" a group?
Dave
-----Original Message-----
From: Hintz, David L [mailto:david.hintz@xxxxxxxxxxx]
Sent: Thursday, April 23, 2009 1:36 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Need test for preceding-sibling
Thanks, Ken! I should have been clearer in my description. Each <a1> and
<a2> should be paired, even though there may be intervening tags. However, an
<a2> without its paired <a1> should not be processed. I'll try your grouping
solution.
Dave
-----Original Message-----
From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx]
Sent: Thursday, April 23, 2009 1:26 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Need test for preceding-sibling
At 2009-04-23 14:01 -0400, Hintz, David L wrote:
>I have a structure like this:
>
><a1/>
><a2/>
><a1/>
><a2/>
><b/>
><c/>
><a2/>
><a1/>
><a2/>
>
>I need to ensure that each <a2> has a preceding <a1>, although there
>may be intervening tags.
This description is a bit imprecise ... do you need them paired, or
will any <a1> before an <a2> suffice?
I ask because in the example you have every <a2> has a preceding
<a1>, some with intervening tags and some without.
But it isn't true that every <a2> has a preceding <a1> that follows
any preceding <a2>.
>I know that
>
> name(preceding-sibling::*[1]
>
>gives me the name of the first preceding sibling, but how do I
>construct a test that gives me only the first preceding <a1> or <a2> tag?
You shouldn't be working with name() because that deals with strings
and not expanded node names in a namespace-safe fashion.
The test that there is any <a1> before the current node being <a2> is:
preceding-sibling::a1
The test that there is an <a1> correspondingly before every <a2> is
approached more easily with XSLT 2 grouping from the parent of those
siblings:
<xsl:for-each-group select="*"
group-ending-with="a2">
<xsl:if test="not(current-group()/self::a1)">
Error! No corresponding a1 for the given a2
</xsl:if>
</xsl:for-each-group>
I hope this helps.
. . . . . . . . . . . . Ken
--
XSLT/XSL-FO/XQuery hands-on training - Los Angeles, USA 2009-06-08
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
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Need test for preceding-s, Hintz, David L | Thread | RE: [xsl] Need test for preceding-s, G. Ken Holman |
| Re: [xsl] When *not* to use XLST..., Shawn Milochik | Date | Re: [xsl] When *not* to use XLST..., Lars Huttar |
| Month |