Skip to content

Instantly share code, notes, and snippets.

@nishantsingh1
Last active June 29, 2017 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishantsingh1/5148401cea921c75b085daa77c7cc2a6 to your computer and use it in GitHub Desktop.
Save nishantsingh1/5148401cea921c75b085daa77c7cc2a6 to your computer and use it in GitHub Desktop.
xquery version "1.0-ml";
declare variable $xslt :=
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- reduce the price by half -->
<xsl:template match="cd/price">
<price>
<xsl:value-of select=". * 0.5"/>
</price>
</xsl:template>
</xsl:stylesheet>;
let $sourcexml :=
<catalog>
<cd>
<title>Red</title>
<artist>The Communards</artist>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
</catalog>
return
xdmp:xslt-eval($xslt, $sourcexml)
(: OUTPUT:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Red</title>
<artist>The Communards</artist>
<company>London</company>
<price xmlns:fo="http://www.w3.org/1999/XSL/Format">3.9</price>
<year>1987</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<company>EMI</company>
<price xmlns:fo="http://www.w3.org/1999/XSL/Format">4.1</price>
<year>1987</year>
</cd>
</catalog> :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment