Last active
December 15, 2015 04:49
-
-
Save greystate/5203973 to your computer and use it in GitHub Desktop.
Demo of how to grab all `<affiliate>` nodes with the `@refID` as specified by the `$refID` variable – *or*, if the $refID variable is empty, take all `<affiliate>`s ...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<root> | |
<affiliate refID="1200">1200</affiliate> | |
<affiliate refID="1201">1201</affiliate> | |
<affiliate refID="1202">1202</affiliate> | |
<affiliate refID="1203">1203</affiliate> | |
<affiliate refID="1204">1204</affiliate> | |
<affiliate refID="1205">1205</affiliate> | |
<affiliate refID="1206">1206</affiliate> | |
<affiliate refID="1207">1207</affiliate> | |
<affiliate refID="1208">1208</affiliate> | |
</root> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<xsl:stylesheet | |
version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
> | |
<xsl:variable name="refID" select="1202" /> | |
<xsl:variable name="affiliates" select="/root/affiliate" /> | |
<xsl:template match="root"> | |
<result> | |
<xsl:apply-templates select=" | |
$affiliates[normalize-space($refID)][@refID = $refID] | |
| | |
$affiliates[not(normalize-space($refID))] | |
" /> | |
</result> | |
</xsl:template> | |
<xsl:template match="affiliate"> | |
<p><xsl:value-of select="." /></p> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
—To test the empty value for $refID, either use "/.." (guaranteed to always be an empty set) or '' :
<xsl:variable name="refID" select="/.." />
or:
<xsl:variable name="refID" select="''" />