[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Feedback on grouping solution
On 26.10.2019 19:03, Rick Quatro rick@xxxxxxxxxxxxxx wrote:
I need to process the <step> child elements so that the <figure> elements are always on the "right" (even-numbered position) in the output. Immediate children of the <procedure> do not factor into the odd/even sequence. Here is my stylesheet. My basic question is: is there a better or more efficient way to do this?
<xsl:mode on-no-match="shallow-copy"/> <xsl:template match="procedure"> <xsl:copy> <xsl:for-each-group select="*" group-adjacent="boolean(self::step)"> <xsl:choose> <xsl:when test="current-grouping-key()"> <xsl:iterate select="current-group()/*"> <xsl:param name="position-in-output" select="1"/> <xsl:apply-templates select="."> <xsl:with-param name="position-in-output" select="$position-in-output"/> </xsl:apply-templates> <xsl:next-iteration> <xsl:with-param name="position-in-output" select="if (self::figure and $position-in-output mod 2 = 1) then $position-in-output + 2 else $position-in-output + 1"/> </xsl:next-iteration> </xsl:iterate> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="current-group()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each-group> </xsl:copy> </xsl:template> <xsl:template match="step/figure"> <xsl:param name="position-in-output"/> <xsl:if test="$position-in-output mod 2 = 1"> <spacer/> </xsl:if> <xsl:next-match/> </xsl:template> Now waiting for Dimitre posting a less "fancy" but equally compact XSLT 1 solution :)
|
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
|