Notes by nogeek
Displaying keyword search results 1 - 11
Created by nogeek on November 27, 2011 12:24:27
Last update: November 27, 2011 12:24:27
There is no XSLT 2.0 support in the JDK as of 7.0. According to Stackoverflow , there are three Java packages that support XSLT 2.0: Saxon IBM WebSphere XML Feature Pack Oracle XDK There are no known support for XSLT in browsers. According to Wikipedia : XSLT is developed by the World Wide Web Consortium (W3C). The most recent version is XSLT 2.0, which reached W3C recommendation status on 23 January 2007. As of 2010, however, XSLT 1.0 is still widely used, as there are no products that support XSLT 2.0 running in the browser, nor on some important server environments such as LAMP. Expressions like this:
format-date(xs:date('1999-12-31'), '[D01] [MNn] ... where format-date is a XSLT 2.0 function and date is a XPath 2.0 constructor...
Created by nogeek on November 03, 2010 20:52:49
Last update: November 23, 2011 08:54:44
My problem is simple: in my XML data, a timestamp is provided as a long integer (number of milliseconds since the "the epoch"). When I do XSLT, I want to display it as a readable string, such as "Mon Nov 01 18:08:48 CDT 2010". After hours of struggle, I found: It's not so easy to get the job done with JDK 1.6 There are tons of garbage on the web in this space (suggestions, code snippets that simply don't work) Simple Xalan extension functions was the only resource that's somewhat informative. Even there some of the examples don't work. Below is a list of what worked and what didn't. This works:
<xsl:stylesheet version="1.0" xmlns:xsl="h... This does not (providing long value to Date constructor): <xsl:stylesheet version="1.0" xmlns:xsl="h......
Created by nogeek on February 08, 2011 13:50:32
Last update: February 08, 2011 13:50:32
I have a template that applies equally for two kinds of nodes (apples and oranges). This is the select to apply same rule to both.
<xsl:apply-templates select="apple|orange">
...
Created by nogeek on February 08, 2011 13:46:18
Last update: February 08, 2011 13:46:18
Simple Java code that does XSLT on an XML file. The transform results go to STDOUT.
import java.io.*;
import javax.xml.parsers....
Created by nogeek on November 11, 2010 00:26:08
Last update: November 11, 2010 00:29:43
This one is even more weird: it worked on Windows but failed on Linux, using default tools JDK1.6.0_20 on both. The exception thrown was:
java.lang.RuntimeException: Invalid conversion fro...
And the stack trace:
java.lang.RuntimeException: Invalid conversion fro...
This was the XSL used:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs...
The problem was , DateUtil.java had two getDate methods, one taking long parameter, the other taking a String parameter. And Java's XSLT get confused about which one to use:
import java.util.Date;
import java.text.SimpleD...
Created by nogeek on November 04, 2010 20:00:15
Last update: November 05, 2010 14:38:43
Following are some bugs in the Xalan jar shipped with JBoss 5.1.0 GA and JBoss 6.0. The Xalan jar file is located in jboss-5.1.0.GA/lib/endorsed ( %JBOSS_HOME%/common/lib for JBoss 6.0).
Test xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
...
Test xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs...
XSLT Java code:
import org.w3c.dom.*;
import javax.xml.parsers....
DateUtil.java
import java.util.Date;
public class DateUti...
XSLT output:
Transformer Factory class: class org.apache.xalan....
Apparently, the output is wrong. The string "A test event" should not have been displayed.
Created by nogeek on November 04, 2010 20:55:31
Last update: November 05, 2010 14:36:09
Following part 1 , change to stylesheet to:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs...
The XSLT output becomes:
java Xslt test.xml test.xsl
Transformer Fac...
Parameter is not passed!
The Xalan version that comes with JDK 1.6 processed this correctly:
java -Djavax.xml.transform.TransformerFactory=com....
Created by nogeek on November 04, 2010 23:25:57
Last update: November 04, 2010 23:26:59
With this XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ev...
and this XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs...
The output of XSLT is:
A test event
Timestamp: 12886515008...
You may not want the title string in the output. There are two ways to do this:
Limit the apply-templates action with a select attribute:
<xsl:template match="/">
<xsl:apply-templat...
Suppress default text node output with an empty template:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs...
Reference: http://www.dpawson.co.uk/xsl/sect2/defaultrule.html
Created by nogeek on November 04, 2010 20:08:02
Last update: November 04, 2010 20:45:25
Use the <xsl:with-param> and <xsl:param> tags to apply parameters to XSL stylesheets:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs...
Created by nogeek on November 04, 2010 20:24:32
Last update: November 04, 2010 20:24:55
XSLT by default writes namespace declarations in the output. Most of the time it's spurious, sometimes outright wrong.
Take this XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ev...
And this XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs...
where DateUtil.java is:
import java.util.Date;
public class DateUti...
The output is (with JDK1.6):
Title: <br xmlns:java="http://xml.apache.org/x...
The namespace declaration went to the <br> element, not the timestamp where it belongs.
To remove the namespace info, add exclude-result-prefixes to the XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs...
Created by nogeek on March 21, 2010 20:30:53
Last update: March 21, 2010 20:37:53
Port 8080 is undoubtedly overused. You may want to change JBOSS to a port other than the default 8080.
Edit the file $JBOSS_HOME/server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml and change the webserver port from 8080 to 8088:
<bean class="org.jboss.services.bi...
The XSLT at the bottom of the file transforms port 8080 in $JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml to 8088 specified in this file.