[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Need test for preceding-sibling

Subject: RE: Need test for preceding-sibling
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 23 Apr 2009 19:24:35 -0400
RE:  Need test for preceding-sibling
At 2009-04-23 16:23 -0400, Hintz, David L wrote:
Now I see that I over-simplified the problem. The XSLT also has to suppress any <a1> that is not paired with an <a2>.

Ouch. You didn't say that.


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?

Yes, it would, so it would not find the isolated <a1/>.


So you want to report any a1 or a2 that does not satisfy the bastardized regex syntax of (a1,[^a1|a2]*,a2)?

I think that can be done with nested groups as shown below with some augmented data added to your original posting.

I hope this helps!

. . . . . . . . Ken

T:\ftemp>type hintz.xml
<test>
<a1/>
<a2/>
<a1/>
<a2/>
<b/>
<c/>
<a2/>
<d/>
<a1/>
<e/>
<a1/>
<f/>
<a2/>
<g/>
</test>

T:\ftemp>xslt2 hintz.xml hintz.xsl
<?xml version="1.0" encoding="UTF-8"?>
<a1/>
<a2/>
<a1/>
<a2/>
<!--Missing paired a1-->
<b/>
<c/>
<a2/>
<d/>
<a1/>
<e/>
<!--Missing paired a2-->
<a1/>
<f/>
<a2/>
<g/>
T:\ftemp>type hintz.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="2.0">

<xsl:output indent="yes"/>

<xsl:template match="test">
  <xsl:for-each-group select="*"
                      group-starting-with="a1">
    <xsl:for-each-group select="current-group()"
                        group-ending-with="a2">
      <xsl:choose>
        <xsl:when test="exists(current-group()/self::a1) =
                        exists(current-group()/self::a2)">
          <xsl:copy-of select="current-group()"/>
        </xsl:when>
        <xsl:when test="current-group()/self::a1">
          <xsl:copy-of select="current-group()"/>
          <xsl:comment>Missing paired a2</xsl:comment><xsl:text>
</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:comment>Missing paired a1</xsl:comment><xsl:text>
</xsl:text>
          <xsl:copy-of select="current-group()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each-group>
  </xsl:for-each-group>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>

--
XSLT/XQuery/XSL-FO 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/m/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/m/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.