Guest User

Untitled

a guest
Dec 9th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. <!-- Sample usage -->
  2. <xsl:apply-templates select="document('sequence.xml')/sequence">
  3. <xsl:with-param name="elements" select="$nodes" /><!-- e.g.: document('nodes.xml')/root/*/* -->
  4. </xsl:apply-templates>
  5.  
  6. <!-- Template (magic) -->
  7. <xsl:template match="sequence">
  8. <xsl:param name="elements" select="/.." /><!-- Default to empty nodeset -->
  9. <xsl:variable name="length" select="count(*)" />
  10. <xsl:for-each select="*">
  11. <xsl:variable name="pos" select="position()" />
  12. <xsl:variable name="name" select="name()" />
  13. <xsl:variable name="offset" select="count(preceding-sibling::*[name() = $name])" />
  14.  
  15. <xsl:apply-templates select="$elements[name() = $name][position() = $offset + 1]">
  16. <!-- This makes it possible to add the @class set on the element in the sequence (or use any other contextual info) -->
  17. <xsl:with-param name="context" select="." />
  18. </xsl:apply-templates>
  19. </xsl:for-each>
  20. </xsl:template>
Add Comment
Please, Sign In to add comment