[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Re: Add element at the end of a variable group of
Chris, how would you like it if someone dropped an unexpected change
in a spec on you at the last minute?! :{)} (you know I'm kidding, right?)
Thankfully, your requirement is readily met by turning my solution around only a slight bit. Instead of looking at it as the new data preceding identified content, consider it as new data following identified content. I hope this helps. . . . . . Ken ~/t/ftemp $ cat chris.xml <?xml version="1.0" encoding="UTF-8"?> <root> <foo/> </root> ~/t/ftemp $ xslt2 chris.xml chris.xsl <?xml version="1.0" encoding="UTF-8"?> <root> <foo/> <moon>Now with more craters!</moon> </root> ~/t/ftemp $ xslt2 charles.xml chris.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 $ xslt2 charles2.xml chris.xsl <?xml version="1.0" encoding="UTF-8"?> <root> <foo/> <bar/> <mercury/> <venus/> <moon>Now with more craters!</moon> <mars/> </root> ~/t/ftemp $ cat chris.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:copy-of select="current-group()"/> <xsl:if test="not(xsd:boolean(current-grouping-key()))"> <moon>Now with more craters!</moon> </xsl:if> </xsl:for-each-group> </xsl:copy> </xsl:template> </xsl:stylesheet> ~/t/ftemp $ At 2021-03-03 00:11 +0000, Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx wrote: Hi Charles, -- 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 |
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|