Skip to content

Instantly share code, notes, and snippets.

@tjunussov
Last active December 22, 2016 15:40
Show Gist options
  • Save tjunussov/2c67f07e727c2622823d4ffaab6351ce to your computer and use it in GitHub Desktop.
Save tjunussov/2c67f07e727c2622823d4ffaab6351ce to your computer and use it in GitHub Desktop.
// Current Context
-- current()/@href
<xsl:apply-templates select="//cd[@title=current()/@ref]"/>
// Template Matchings
-- Attribute Value StartWith
<xsl:template match="input[starts-with(@type, '$')]">
-- Tag Proxying
<xsl:template match="input">
.. smth
<xsl:apply-templates select="self::node()" mode="controls">
// Formating
<xsl:decimal-format name="money" decimal-separator="," NaN="-" grouping-separator="."/>
<xsl:decimal-format name="spaces" grouping-separator=" " />
<xsl:value-of select="format-number(sum(data/deliveredExpireCount[number(.)=number(.)]),'###.###','money')"/>
<xsl:value-of select="format-number(sum(data/receivedAmount[number(.)=number(.)]),'###.### ₸','money')"/>
// Text from Attribute or Content
<xsl:value-of select="@title[.] | text()[.]"/>
// EXSLT example
<xsl:variable name="nav" select="exslt:node-set($navXml)/nav"/>
<xsl:variable name="navXml">
<nav>
<h1>Dashboard</h1>
</nav>
</xsl:variable>
// Exclude node
<xsl:apply-templates select="node()[not(self::header | self::footer)]" />
// Self Node apply
<xsl:template match="input">
<xsl:apply-templates select="self::node()" mode="controls"/>
</xsl:template>
<xsl:template match="input[@type='text']" mode="controls">
<input type="text" value="{@value}"/>
</xsl:template>
// Pass thru tags
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<xsl:copy-of select="@*|node()"/>
// Default values ( inline if/else )
<value-of select="{concat(@testValue,substring('defaultValue', 1 div not(@testValue)))}"/>
/*********************************************/
/*********************************************/
/*********************************************/
/*********************************************/
/*********************************************/
*************** Javascript XML XSL ***********/
/*********************************************/
/*********************************************/
/*********************************************/
/*********************************************/
// Extracting xml-stylesheet PI ( NodeJs Libxmljs )
var path = xml.get('//processing-instruction()[name() = "xml-stylesheet"]');
console.log(path.toString()); // prints "<?xml-stylesheet type="text/xsl" href="_templates/template.xsl"?>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment