Skip to content

Instantly share code, notes, and snippets.

View greystate's full-sized avatar
:octocat:
Octocatering

Chriztian Steinmeier greystate

:octocat:
Octocatering
View GitHub Profile
<xsl:if test="record/datafield[@tag = '245'] and record/datafield/subfield[@code = 'a']">
...
</xsl:if>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Assumes an XML document with multiple <order> elements inside a wrapping <orders> element.
-->
<!DOCTYPE xsl:stylesheet [
<!-- Close your eyes and take a leap of faith! -->
<!ENTITY countAllOccurences "sum(ancestor::orders/order/orderLine[properties/productNumber = current()/following-sibling::productNumber]/@quantity)">
]>
<xsl:stylesheet
version="1.0"
@greystate
greystate / dynamicsort.xslt
Created December 21, 2010 13:18
Dynamically determining sort order in XSLT (in Umbraco) with QueryString parameter
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
@greystate
greystate / occurrences.xslt
Created January 18, 2011 22:40
One-liner for counting the number of occurrences of $char in $string
<xsl:value-of select="string-length($string) - string-length(translate($string, $char, ''))" />
@greystate
greystate / filterBy.js
Created January 20, 2011 10:03
A couple of helpers...
function filterBy(selector) {
var c = selector.value, loc = document.location, q = loc.search;
q = addOrReplaceQueryStringParam(q, "category", c);
document.location = loc.pathname + q;
}
function gotoCategory(selector) {
var c = selector.value;
document.location = "/produkter?category=" + encodeURIComponent(c);
}
@greystate
greystate / conditional-include.xslt
Created January 21, 2011 10:31
A way to fake including multiple stylesheets and choosing which to use
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
@greystate
greystate / apos-replace.xslt
Created January 26, 2011 14:19
Replace ' in RTE
<xsl:variable name="apos"><![CDATA[']]></xsl:variable>
<xsl:value-of select="translate(RTEFieldName, $apos, '_')" disable-output-escaping="yes" />
@greystate
greystate / one-line-toggle.xslt
Created February 8, 2011 23:32
One-liner to assign a variable one of two values, dependent on condition (XSLT 1.0, that is)
<!-- Selects 'YES' if CONDITION is true() -->
<xsl:value-of select="substring('YES|NO', not(CONDITION) * 4 + 1, 3)" />
<!-- Selects 'NO' if CONDITION is true() -->
<xsl:value-of select="substring('YES|NO', boolean(CONDITION) * 4 + 1, 3)" />
<!--
Notes:
* Need both versions because the longer value must be the first of the two
@greystate
greystate / multiplication-table.xslt
Created February 23, 2011 00:33
Building a Multiplication Table with XSLT
<?xml version="1.0" encoding="utf-8"?>
<!--
Triggered by Darren Ferguson's hilarious "The Umbraco XSLT for loop"
(http://www.darren-ferguson.com/2011/2/22/the-umbraco-xslt-for-loop),
and Lee Kelleher's follow-up: http://pastebin.com/92UXcYUQ,
I thought I'd document the coolest way I've seen it done, which does not even use
recursion... only requirement is that the source document has at least as many "nodes"
as the loop needs.
(If there's too few nodes this stylesheet could be modified to use itself as "counter",
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />