M
mjarends
I'm using JAXP for XSLT - I'm using the examples from
http://www.w3.org/TR/xslt#section-Examples. I'm using the following XML
file:
<?xml version="1.0" encoding="UTF-8"?>
<sales>
<division id="North">
<revenue>10</revenue>
<growth>9</growth>
<bonus>7</bonus>
</division>
<division id="South">
<revenue>4</revenue>
<growth>3</growth>
<bonus>4</bonus>
</division>
<division id="West">
<revenue>6</revenue>
<growth>-1.5</growth>
<bonus>2</bonus>
</division>
</sales>
and the following XSL file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
<xslutput method="xml" indent="yes" media-type="image/svg"/>
<xsl:template match="/">
<svg width = "3in" height="3in">
<g style = "stroke: #000000">
<!-- draw the axes -->
<line x1="0" x2="150" y1="150" y2="150"/>
<line x1="0" x2="0" y1="0" y2="150"/>
<text x="0" y="10">Revenue</text>
<text x="150" y="165">Division</text>
<xsl:for-each select="sales/division">
<!-- define some useful variables -->
<!-- the bar's x position -->
<xsl:variable name="pos"
select="(position()*40)-30"/>
<!-- the bar's height -->
<xsl:variable name="height"
select="revenue*10"/>
<!-- the rectangle -->
<rect x="{$pos}" y="{150-$height}"
width="20" height="{$height}"/>
<!-- the text label -->
<text x="{$pos}" y="165">
<xsl:value-of select="@id"/>
</text>
<!-- the bar value -->
<text x="{$pos}" y="{145-$height}">
<xsl:value-of select="revenue"/>
</text>
</xsl:for-each>
</g>
</svg>
</xsl:template>
</xsl:stylesheet>
The result of running the JAXP code is:
<?xml version="1.0" encoding="UTF-8"?>
10
9
7
4
3
4
6
-1.5
2
and is missing the XML elements within the result. The JAXP code that
I'm using is the following:
// Create the tranformation object
TransformerFactory factory = TransformerFactory.newInstance();
StreamSource xslSource = new StreamSource(xslFile);
xslSource.setSystemId(xslFile);
Templates template = factory.newTemplates(xslSource);
// Set the source that the tranformation will be
performed on
Source source = new DOMSource(xmlInput);
// Create a output stream to hold the results
StreamResult result = new StreamResult(output);
// Transform the document
Transformer transformer = template.newTransformer();
transformer.transform(source, result);
Does anyone have any idea as to why the XML elements are not being
output? Thanks in advance.
http://www.w3.org/TR/xslt#section-Examples. I'm using the following XML
file:
<?xml version="1.0" encoding="UTF-8"?>
<sales>
<division id="North">
<revenue>10</revenue>
<growth>9</growth>
<bonus>7</bonus>
</division>
<division id="South">
<revenue>4</revenue>
<growth>3</growth>
<bonus>4</bonus>
</division>
<division id="West">
<revenue>6</revenue>
<growth>-1.5</growth>
<bonus>2</bonus>
</division>
</sales>
and the following XSL file:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">
<xslutput method="xml" indent="yes" media-type="image/svg"/>
<xsl:template match="/">
<svg width = "3in" height="3in">
<g style = "stroke: #000000">
<!-- draw the axes -->
<line x1="0" x2="150" y1="150" y2="150"/>
<line x1="0" x2="0" y1="0" y2="150"/>
<text x="0" y="10">Revenue</text>
<text x="150" y="165">Division</text>
<xsl:for-each select="sales/division">
<!-- define some useful variables -->
<!-- the bar's x position -->
<xsl:variable name="pos"
select="(position()*40)-30"/>
<!-- the bar's height -->
<xsl:variable name="height"
select="revenue*10"/>
<!-- the rectangle -->
<rect x="{$pos}" y="{150-$height}"
width="20" height="{$height}"/>
<!-- the text label -->
<text x="{$pos}" y="165">
<xsl:value-of select="@id"/>
</text>
<!-- the bar value -->
<text x="{$pos}" y="{145-$height}">
<xsl:value-of select="revenue"/>
</text>
</xsl:for-each>
</g>
</svg>
</xsl:template>
</xsl:stylesheet>
The result of running the JAXP code is:
<?xml version="1.0" encoding="UTF-8"?>
10
9
7
4
3
4
6
-1.5
2
and is missing the XML elements within the result. The JAXP code that
I'm using is the following:
// Create the tranformation object
TransformerFactory factory = TransformerFactory.newInstance();
StreamSource xslSource = new StreamSource(xslFile);
xslSource.setSystemId(xslFile);
Templates template = factory.newTemplates(xslSource);
// Set the source that the tranformation will be
performed on
Source source = new DOMSource(xmlInput);
// Create a output stream to hold the results
StreamResult result = new StreamResult(output);
// Transform the document
Transformer transformer = template.newTransformer();
transformer.transform(source, result);
Does anyone have any idea as to why the XML elements are not being
output? Thanks in advance.