Skip to content

Instantly share code, notes, and snippets.

@brendo brendo/master.xml
Last active Mar 15, 2019

Embed
What would you like to do?
<data>
<people>
<item id='1'>Fred</item>
<item id='2'>Jane</item>
<item id='3'>Bob</item>
<item id='4'>Mary</item>
<item id='6'>Tom</item>
</people>
<people-details>
<entry id='1'>
<name>Fred</name>
<show>Yes</show>
</entry>
<entry id='2'>
<name>Jane</name>
<show>No</show>
</entry>
<entry id='3'>
<name>Bob</name>
<show>Yes</show>
</entry>
<entry id='4'>
<name>Mary</name>
<show>No</show>
</entry>
<entry id='5'>
<name>Max</name>
<show>Yes</show>
</entry>
<entry id='6'>
<name>Tom</name>
<show>Yes</show>
</entry>
</people-details>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<data>
<xsl:variable name='folks'>
<xsl:for-each select='data/people/item'>
<xsl:copy-of select='/data/people-details/entry[@id = current()/@id and show = "Yes"]' />
</xsl:for-each>
</xsl:variable>
<xsl:apply-templates select='exsl:node-set($folks)/entry[position() &lt; 3]' mode='show-people' />
</data>
</xsl:template>
<xsl:template match="entry" mode='show-people'>
<name>
<xsl:value-of select='name' />
</name>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.