[Home] [By Thread] [By Date] [Recent Entries]
I would approach this as a grouping issue and not a matching issue.
I hope this helps. . . . . . Ken ~/t/ftemp $ cat charles.xml <?xml version="1.0" encoding="UTF-8"?> <root> <foo/> <bar/> <mercury/> <venus/> <earth earth-type="round"/> <earth earth-type="flat"/> <mars/> </root> ~/t/ftemp $ xslt2 charles.xml charles.xsl <?xml version="1.0" encoding="UTF-8"?> <root> <foo/> <bar/> <mercury/> <venus/> <moon>Now with more craters!</moon> <earth earth-type="round"/> <earth earth-type="flat"/> <mars/> </root> ~/t/ftemp $ cat charles.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xsd" version="2.0"> <xsl:output indent="yes"/> <xsl:template match="root">
<xsl:copy>
<xsl:for-each-group select="*"
group-adjacent="self::earth or self::mars">
<xsl:if test="xsd:boolean(current-grouping-key())">
<moon>Now with more craters!</moon>
</xsl:if>
<xsl:copy-of select="current-group()"/>
</xsl:for-each-group>
</xsl:copy>
</xsl:template></xsl:stylesheet> ~/t/ftemp $ cat charles2.xml <?xml version="1.0" encoding="UTF-8"?> <root> <foo/> <bar/> <mercury/> <venus/> <mars/> </root> ~/t/ftemp $ xslt2 charles2.xml charles.xsl <?xml version="1.0" encoding="UTF-8"?> <root> <foo/> <bar/> <mercury/> <venus/> <moon>Now with more craters!</moon> <mars/> </root> ~/t/ftemp $ At 2021-03-03 00:01 +0000, Charles O'Connor coconnor@xxxxxxxxxxxx wrote: Hi all, -- Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ | Check our site for free XML, XSLT, XSL-FO and UBL developer resources | Streaming hands-on XSLT/XPath 2 training class @US$125 (5 hours free) | Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |
|

Cart



