C
crazydiode
HI All,
I am new to XSLT. I am trying to use xslt with xml in my java code. I
am basically trying to replace one node of the original xml with my own
node. I defined the xslt as follows:
<xsl:stylesheet xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="directions">
myNode = <xsl:value-of select="directions"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template/>`
</xsl:stylesheet>
where "directions" is the node that i want to replace with "mynode".
But when i run it, this doesnt happpen... I dont know what wrong i am
doing here.
Here's the original XML that i want to transform
<report latitude="41.2° N" longitude="71.6° W">
<locality>Block Island</locality>
<temperature units="°C">16</temperature>
<humidity>88%</humidity>
<dewpoint units="°C">14</dewpoint>
<wind>
<direction>
<directions>NE
</directions>
</direction>
<speed units="km/h">16.1</speed>
<gust units="km/h">31</gust>
</wind>
<pressure units="hPa">1014</pressure>
<condition>overcast</condition>
<visibility>13 km</visibility>
</report>
My JavaCode:
Source xsltSource = new
StreamSource("T:/Technology/Seena/DartAdTesting/DartAdTags.xsl"); //
Source of XSL File
Source source = new DOMSource(doc); // Document to be transformed
Result result = new StreamResult(System.out); // Where to put result
document (console here)
//Start off with a factory object
TransformerFactory tf = TransformerFactory.newInstance();
//Use the factory to read the XSLT file into a Templates object
Templates transformation = tf.newTemplates(xsltSource);
//Create a Transformer object from the Templates object
Transformer transformer = transformation.newTransformer();
//Finally, perform the transformation
transformer.transform(source, result); // This will output the result.
Any help is very much appreciated.. thanks a lott..
I am new to XSLT. I am trying to use xslt with xml in my java code. I
am basically trying to replace one node of the original xml with my own
node. I defined the xslt as follows:
<xsl:stylesheet xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="directions">
myNode = <xsl:value-of select="directions"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template/>`
</xsl:stylesheet>
where "directions" is the node that i want to replace with "mynode".
But when i run it, this doesnt happpen... I dont know what wrong i am
doing here.
Here's the original XML that i want to transform
<report latitude="41.2° N" longitude="71.6° W">
<locality>Block Island</locality>
<temperature units="°C">16</temperature>
<humidity>88%</humidity>
<dewpoint units="°C">14</dewpoint>
<wind>
<direction>
<directions>NE
</directions>
</direction>
<speed units="km/h">16.1</speed>
<gust units="km/h">31</gust>
</wind>
<pressure units="hPa">1014</pressure>
<condition>overcast</condition>
<visibility>13 km</visibility>
</report>
My JavaCode:
Source xsltSource = new
StreamSource("T:/Technology/Seena/DartAdTesting/DartAdTags.xsl"); //
Source of XSL File
Source source = new DOMSource(doc); // Document to be transformed
Result result = new StreamResult(System.out); // Where to put result
document (console here)
//Start off with a factory object
TransformerFactory tf = TransformerFactory.newInstance();
//Use the factory to read the XSLT file into a Templates object
Templates transformation = tf.newTemplates(xsltSource);
//Create a Transformer object from the Templates object
Transformer transformer = transformation.newTransformer();
//Finally, perform the transformation
transformer.transform(source, result); // This will output the result.
Any help is very much appreciated.. thanks a lott..