[Home] [By Thread] [By Date] [Recent Entries]
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: 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
|

Cart



