Upgrading XSLT 1.0 to XSLT 2.0

What is involved in upgrading from XSLT 1.0 to 2.0? 1 – What are the possible reasons for upgrading? If you are an XSLT programmer you’ll benefit largely from the more convenient and expressive XSLT 2.0 language + XPath 2.0 and the new XDM (XPath Data Model). You may want to watch this XSLT 2.0 … Read more

XSL xsl:template match=”/”

The value of the match attribute of the <xsl:template> instruction must be a match pattern. Match patterns form a subset of the set of all possible XPath expressions. The first, natural, limitation is that a match pattern must select a set of nodes. There are also other limitations. In particular, reverse axes are not allowed … Read more

How do I run an XSLT file?

You have two options: Let the browser do it. Pass the XML with a reference to the XSLT and the browser (IE 6 or lower might have problems) will render it as (X)HTML: <?xml-stylesheet type=”text/xsl” href=”http://www.example.com/my-xslt.xsl” ?> Do it server-side. Most languages have methods for accepting XSLT and XML data, then outputting (X)HTML. Here are … Read more

Current node vs. Context node in XSLT/XPath?

The current node is whatever the template is currently operating on. Normally this happens to also be the context node, but the context node has special meaning within a nested XPath expression (the part in square brackets). There, it refers to whatever node is currently being tested for a match. Hence, the context node changes … Read more

XSLT: How to change an attribute value during ?

This problem has a classical solution: Using and overriding the identity template is one of the most fundamental and powerful XSLT design patterns: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:param name=”pNewType” select=”‘myNewType'”/> <xsl:template match=”node()|@*”> <xsl:copy> <xsl:apply-templates select=”node()|@*”/> </xsl:copy> </xsl:template> <xsl:template match=”property/@type”> <xsl:attribute name=”type”> <xsl:value-of select=”$pNewType”/> </xsl:attribute> </xsl:template> </xsl:stylesheet> When applied on this XML document: <t> … Read more

Using an HTML entity in XSLT (e.g.  )

You can use CDATA section <xsl:text disable-output-escaping=”yes”><![CDATA[&nbsp;]]></xsl:text> or you can describe &nbsp in local DTD: <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp “&#160;”> ]> or just use &#160; instead of &nbsp;

XSLT with XML source that has a default namespace set to xmlns

You need to declare the namespace in your XSLT, and use it in XPath expressions. E.g.: <xsl:stylesheet … xmlns:my=”http://www.mysite.com”> <xsl:template match=”/my:MyRoot”> … </xsl:template> </xsl:stylesheet> Note that you must provide some prefix if you want to refer to elements from that namespace in XPath. While you can just do xmlns=”…” without the prefix, and it will … Read more

Is there an XSL “contains” directive?

Sure there is! For instance: <xsl:if test=”not(contains($hhref, ‘1234’))”> <li> <a href=”https://stackoverflow.com/questions/569908/{$hhref}” title=”{$pdate}”> <xsl:value-of select=”title”/> </a> </li> </xsl:if> The syntax is: contains(stringToSearchWithin, stringToSearchFor)

What are good CLI tools for JSON?

I just found this: http://stedolan.github.io/jq/ “jq is a lightweight and flexible command-line JSON processor.” 2014 update: @user456584 mentioned: There’s also the ‘json’ command (e.g. ‘jsontool’). I tend to prefer it over jq. Very UNIX-y. Here’s a link to the project: github.com/trentm/json – in the json README at http://github.com/trentm/json there is a long list of similar … Read more