Before we deploy our XSL servlet, let’s look at some simple transforms from the command line.
First, a simple transform that detects the root node and then outputs the xalan environment. Naturally, this will only work when you’re using xalan .
1
2
3
4
5
6
7
8
9
10<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:copy-of select="xalan:checkEnvironment()"/>
</xsl:template>
</xsl:stylesheet>
1 | 1 $ cat input.xml |
Next, let’s look at the “identity” transform. There is a single template directive that matches on attributes or elements (@* and node() respectively). For each attribute or element entity, we copy the current attribute or element and then we recursively apply the template to any children of the current element.
1
2
3
4
5
6
7
8
9
10<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>1
3 $ java org.apache.xalan.xslt.Process -IN input.xml -XSL metadata/xsl/echo.xsl
<?xml version="1.0"?>
<root>
<child remove="attribute">
<grandchild>foo</grandchild>
</child>
<remove>
<alpha/>
</remove>
</root>
1
2
3
4
5
6
7
8
9
10
11
12
13
14<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="@*|node()" priority="10">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="remove" priority="20">
</xsl:template>
</xsl:stylesheet>1
4 $ java org.apache.xalan.xslt.Process -IN input.xml -XSL metadata/xsl/remove.xsl
<?xml version="1.0" encoding="UTF-8"?><root>
<child remove="attribute">
<grandchild>foo</grandchild>
</child>
</root>
Sep 12: Adding a REST Service to SoapUI
Oct 2: Using XSL Param