XML

Getting a substring before the last occurrence of a character in XSLT 1.0

With XSLT 2.0 a method is provided, which splits a string by a specific delimiter (e.g. commas, spaces or other) quite easily.

<xsl:variable name="subString" 
        select="substring-before-last($arg, $delim)"></xsl:variable>

This function returns the part of $arg which appears before the last occurrence of $delim. If $arg does not contain $delim, a zero-length string is returned.

If you split the string “XPath-is-fun” as $arg with $delim “-” you will get the following result:

XPath-is

Unfortunately, this function is not provided in XSLT 1.0. But there is a possibility of realizing this without any 3rd party libraries (e.g. EXSLT). The following example shows, how this can be done with XSLT 1.0.

Readmore…

Tagged , ,

Tokenize a String in XSLT 1.0

With XSLT 2.0 a method is provided, which tokenizes a string by a specific delimiter (e.q. commas, spaces or other) quite easily.

<xsl:variable name="stringList" select="tokenize('XPath is fun', ' ')"/>

This subsequently can be used to iterate over the individual String elements:

<xsl:for-each select="$stringList">
	<xsl:value-of select="." />
</xsl:for-each>

The result of this easy method call is tokenized by spaces, so we get:

"XPath", "is", "fun"

Unfortunately, this function is not provided in XSLT 1.0, but there is the possibility of realizing this without any 3rd party libraries (e.q. EXSLT). The following example shows, how this can be done with XSLT 1.0.

Readmore…

Tagged , ,

Getting current date and time in XSLT 1.0

With XSLT 2.0, a method is provided, which quite simply determines the current date or time.

<xsl:value-of  select="current-dateTime()"/>

Unfortunately, this is not possible with XSLT 1.0, but there is the option to realize this using Java or JavaScript resources within the stylesheet. Here is an example, using Java, that works with Xalan and is default available in the ORACLE JRE.

Readmore…

Tagged , ,

XHTML validation against DTD schema in Java

Recently I had the problem of validating XHTML file using DTD schema and Java. As for DTD validation to find little on the Internet, I would like to explain briefly how this is possible by simply using Java resources.

Readmore…

Tagged , , ,