How to execute XSLT 2.0 with ant?

The problem is that while Saxon is added to the classpath, the default JAXP mechanism to determine which TransformerFactory is used and it will use the default that is Xalan. You either need to: Set javax.xml.transform.TransformerFactory system variable to net.sf.saxon.TransformerFactoryImpl, Add saxon9.jar to the CLASSPATH system variable, or Use <factory name=”net.sf.saxon.TransformerFactoryImpl”/> inside the xslt element

Replace special characters in XSLT

There is a pure XSLT way to do this. <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output method=”xml” indent=”yes” omit-xml-declaration=”yes”/> <xsl:variable name=”vAllowedSymbols” select=”‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'”/> <xsl:template match=”node() | @*”> <xsl:copy> <xsl:apply-templates select=”node() | @*”/> </xsl:copy> </xsl:template> <xsl:template match=”text()”> <xsl:value-of select=” translate( ., translate(., $vAllowedSymbols, ”), ” ) “/> </xsl:template> </xsl:stylesheet> Result against this sample: <t> <Name>O’Niel</Name> <Name>St Peter</Name> <Name>A.David</Name> </t> Will … Read more

XSLT concat string, remove last comma

This is very easy to accomplish with XSLT (No need to capture the results in a variable, or to use special named templates): I. XSLT 1.0: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output method=”text”/> <xsl:template match=”/*/*”> <xsl:for-each select= “Locality/text() | CollectorAndNumber/text() | Institution/text() | Distribution/text() | Note/text() ” > <xsl:value-of select=”.”/> <xsl:if test=”not(position() = last())”>,</xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet> … Read more

How to convert json to xml using xslt

My work on JSON parsing doesn’t cover the full JSON grammar. And the task of “translating” any JSON document to an XML document doesn’t have a solution. There are JSON constructs, which cannot be translated to XML without defining additional conventions and introducing additional elements — so the final XML structure isn’t a true and … 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;

Check if a string is null or empty in XSLT

test=”categoryName != ”” Edit: This covers the most likely interpretation, in my opinion, of “[not] null or empty” as inferred from the question, including it’s pseudo-code and my own early experience with XSLT. I.e., “What is the equivalent of the following Java?”: // Equivalent Java, NOT XSLT !(categoryName == null || categoryName.equals(“”)) For more details … Read more

Can an XSLT insert the current date?

XSLT 2 Date functions are available natively, such as: <xsl:value-of select=”current-dateTime()”/> There is also current-date() and current-time(). XSLT 1 Use the EXSLT date and times extension package. Download the date and times package from GitHub. Extract date.xsl to the location of your XSL files. Set the stylesheet header. Import date.xsl. For example: <xsl:stylesheet version=”1.0″ xmlns:date=”http://exslt.org/dates-and-times” … Read more