Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- Sample usage -->
- <xsl:apply-templates select="document('sequence.xml')/sequence">
- <xsl:with-param name="elements" select="$nodes" /><!-- e.g.: document('nodes.xml')/root/*/* -->
- </xsl:apply-templates>
- <!-- Template (magic) -->
- <xsl:template match="sequence">
- <xsl:param name="elements" select="/.." /><!-- Default to empty nodeset -->
- <xsl:variable name="length" select="count(*)" />
- <xsl:for-each select="*">
- <xsl:variable name="pos" select="position()" />
- <xsl:variable name="name" select="name()" />
- <xsl:variable name="offset" select="count(preceding-sibling::*[name() = $name])" />
- <xsl:apply-templates select="$elements[name() = $name][position() = $offset + 1]">
- <!-- This makes it possible to add the @class set on the element in the sequence (or use any other contextual info) -->
- <xsl:with-param name="context" select="." />
- </xsl:apply-templates>
- </xsl:for-each>
- </xsl:template>
Add Comment
Please, Sign In to add comment