473,511 Members | 16,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with XSLT and Java

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..

May 12 '06 #1
5 1391
You haven't shown us how you built that DOM... You are using the DOM
Level 2 calls (createElementNS and so on), *NOT* the Level 1 calls
(createElement without namespace awareness), right? Depending on your
XSLT processor, a namespace-unaware DOM may not be supported even if you
aren't using namespaces.
May 12 '06 #2
I am not sure what you meant by "how you built that DOM".. i am using a
domsource and then using transfomer to get the final xml....

May 12 '06 #3
crazydiode wrote:
I am not sure what you meant by "how you built that DOM".. i am using a
domsource and then using transfomer to get the final xml....


What is the argument to the DOMSource's constructor? Presumably a DOM,
since if you were reading from a file you would have used a StreamSource.

So: Where did that DOM come from?
May 12 '06 #4
Yeah.. i am creating the DOMSOurce as

DOMSource source = new DOMSource(node); // Document to be transformed
StreamResult result = new StreamResult(fos);
and this is in saveXMLDocument(Node node) method, so i am passing the
node to the DOMSource constructor...
am i making any mistkae here ??

May 12 '06 #5
crazydiode wrote:
Yeah.. i am creating the DOMSOurce as
DOMSource source = new DOMSource(node);


I say again: First thing I would check is that your node is indeed the
document structure you think it is, and (because some processors are
picky about this) was constructed using DOM Level 2 namespace-aware nodes.
May 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3997
by: Thomas Honold | last post by:
Hi there, I want to generate C++ or Java code by script, e.g. classes with getter/setter methods. Someone told me that nowadays it is done with XML and XSLT. I should use - XML File which...
0
2894
by: Dominique Bejean | last post by:
Hello, I am having a problem doing an XSLT transformation using Java. I have a XML document as a DOM Document object, wrap the Document object with a DOMSource object, and do the...
2
3382
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
4
10299
by: Thomas Mann | last post by:
Hi, how can I make my XSLT-stylesheet insert a timestamp (date/time) into the output file ? Regards Thomas
0
1248
by: Bloody Viking | last post by:
I'm using a variation on Donald Leslie's JAXPTransletMultipleTransformations.java...
6
3155
by: Robbie Baldock | last post by:
Hi - I'm a bit of a newbie to the world of XSLTs but am trying to call a Java method on a parameter passed into an XSLT but am having problems. I've stripped the XSLT down to its bare bones: ...
7
4102
by: RC | last post by:
First, let me say I couldn't find a group discuss XML/XSLT. So I only choose the closest groups to post this message. Here is part of my *.xsl file <xsl:stylesheet...
5
1664
by: cybernerdsx2 | last post by:
Hi, I am new to XSLT and I would like to use Java to read up the XSLT content and add in a few tags in into the template below: <xsl:template name="hwSpecs"> <!-- adding new tags into here...
6
3710
by: John Larson | last post by:
Hi All, I am some information from INSPEC database records in XML to build a relational database of my own. I am currently trying to extract information by doing an XSLT transform of the XML...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.