473,785 Members | 2,219 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:styleshe et xmlns:xsl=" http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="directio ns">
myNode = <xsl:value-of select="directi ons"/>
</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>Blo ck Island</locality>
<temperature units="°C">16</temperature>
<humidity>88% </humidity>
<dewpoint units="°C">14</dewpoint>
<wind>
<direction>
<directions>N E
</directions>
</direction>
<speed units="km/h">16.1</speed>
<gust units="km/h">31</gust>
</wind>
<pressure units="hPa">101 4</pressure>
<condition>over cast</condition>
<visibility>1 3 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(Sy stem.out); // Where to put result
document (console here)

//Start off with a factory object
TransformerFact ory tf = TransformerFact ory.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.tra nsform(source, result); // This will output the result.

Any help is very much appreciated.. thanks a lott..

May 12 '06 #1
5 1400
You haven't shown us how you built that DOM... You are using the DOM
Level 2 calls (createElementN S 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(fo s);
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
4017
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 contains classnames and private members - XSLT to transform them to code files - XSLT processor which does the conversion
0
2920
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 transformation. However, the transformation does not work. None of the templates in the XSLT source are Matched, except for the root template. The code is as follows:
2
3407
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 happening when I put my XML files and the .xsl files on my ISP's system for my home page. If I try to open the XML files in Netscape 7.0 on my own machine (ie, not on the ISP's system), the pages convert file and the result is displayed in HTML.
4
10314
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
1263
by: Bloody Viking | last post by:
I'm using a variation on Donald Leslie's JAXPTransletMultipleTransformations.java (http://www.cs.helsinki.fi/group/xmltools/formatters/xalan/xalan-j_2_1_0/samples/translets/JAXPTransletMultipleTransformations.java), and it seems to work just fine. But then I copied it, the xml and the xslt over to another machine (both SPARC boxes) and got a strange result: character entities are getting translated strangely. For instance, &ecirc; is...
6
3171
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: <xsl:stylesheet version="1.0" xmlns:java="http://xml.apache.org/xslt/java"
7
4126
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 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" xmlns:my-javascript-ext="my-ext1" extension-element-prefixes="my-javascript-ext"
5
1687
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 from Java --> </xsl:template> So, what kind of parser or tools can I use in my Java source code to
6
3730
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 files into a tab-separated text file that I want to import into the database. I have run into the following problem: in some documents there are missing elements, for instance the volume and issue number of an article is not there (i.e. it is defined...
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10096
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4055
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 we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.