473,776 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT output missing XML elements

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:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"

xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd">

<xsl:output 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">Revenu e</text>
<text x="150" y="165">Divisio n</text>
<xsl:for-each select="sales/division">
<!-- define some useful variables -->

<!-- the bar's x position -->
<xsl:variable name="pos"
select="(positi on()*40)-30"/>

<!-- the bar's height -->
<xsl:variable name="height"
select="revenue *10"/>

<!-- the rectangle -->
<rect x="{$pos}" y="{150-$height}"
width="20" height="{$heigh t}"/>

<!-- 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
TransformerFact ory factory = TransformerFact ory.newInstance ();
StreamSource xslSource = new StreamSource(xs lFile);
xslSource.setSy stemId(xslFile) ;
Templates template = factory.newTemp lates(xslSource );

// Set the source that the tranformation will be
performed on
Source source = new DOMSource(xmlIn put);

// Create a output stream to hold the results
StreamResult result = new StreamResult(ou tput);

// Transform the document
Transformer transformer = template.newTra nsformer();
transformer.tra nsform(source, result);

Does anyone have any idea as to why the XML elements are not being
output? Thanks in advance.

Feb 14 '06 #1
7 3540
xsl:value-of copies only the text content of the node. You probably
wanted xsl:copy-of.
Feb 14 '06 #2
The problem is that the XSL is correct - I took it directly from the
XSLT w3c web site. The result of the transformation should look like
this:

<svg width="3in" height="3in"
xmlns="http://www.w3.org/Graphics/SVG/svg-19990412.dtd">
<g style="stroke: #000000">
<line x1="0" x2="150" y1="150" y2="150"/>
<line x1="0" x2="0" y1="0" y2="150"/>
<text x="0" y="10">Revenu e</text>
<text x="150" y="165">Divisio n</text>
<rect x="10" y="50" width="20" height="100"/>
<text x="10" y="165">North </text>
<text x="10" y="45">10</text>
<rect x="50" y="110" width="20" height="40"/>
<text x="50" y="165">South </text>
<text x="50" y="105">4</text>
<rect x="90" y="90" width="20" height="60"/>
<text x="90" y="165">West</text>
<text x="90" y="85">6</text>
</g>
</svg>

However when I use the JAXP code above I get the output that I
specified.

Feb 14 '06 #3
OK, that's what I get for shooting from the hip rather than stopping to
check it in detail.

Ran it myself, using Xalan via the TrAX API, and it runs fine.

So the next question is, what are you doing with the output? It sounds
as if you're running it through something which is discarding all the
element markup.
Here's a trivial TrAX wrapper; try this and see what it does for you.

import java.io.FileNot FoundException;
public class TrAX {

/**
* @param args
*/
public static void main(String[] args) throws FileNotFoundExc eption
{
String xsl=(args.lengt h>0) ? args[0] : "test.xsl";
String xml=(args.lengt h>1) ? args[1] : "test.xml";
java.io.PrintSt ream out=(args.lengt h>2)
? new java.io.PrintSt ream("test.out" )
: System.out;

try {
// 1. Instantiate a TransformerFact ory.
javax.xml.trans form.Transforme rFactory tFactory =
javax.xml.trans form.Transforme rFactory.newIns tance();

// 2. Use the TransformerFact ory to process the
// stylesheet Source and generate a Transformer.
javax.xml.trans form.Transforme r transformer =
tFactory.newTra nsformer(
new javax.xml.trans form.stream.Str eamSource(xsl)
);

// 3. Use the Transformer to transform an
// XML Source and send the output to a Result.
transformer.tra nsform(
new javax.xml.trans form.stream.Str eamSource(xml),
new javax.xml.trans form.stream.Str eamResult(out)
);
} catch (Exception e) {
e.printStackTra ce();
}
}

}

}
Feb 14 '06 #4
> Source source = new DOMSource(xmlIn put);

You didn't tell us what xmlInput is -- specifically, what the
implementation is and how it's being constructed.

(Are you using the obsolete createElement() , createAttribute (),
setAttribute() calls rather than the namespace-aware createElementNS (),
createAttribute NS(), setAttributeNS( )?)
StreamResult result = new StreamResult(ou tput);


You didn't tell us what output is. It may be doing something to the
result before you see it.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 14 '06 #5
Yep - sorry just saw that. The xmlInput is constructed outside of the
method specified above in the following manner:
DocumentBuilder builder = getDocumentBuil der();
// Parser the input source
Document doc = builder.parse(n ew FileInputStream (EXAMPLE1_XML)) ;

Node example1DocRoot = example1Doc.get DocumentElement ();
The example1DocRoot is the xmlInput.

The output is constructed outside of the method in the following
manner:
FileOutputStrea m fos = new FileOutputStrea m(EXAMPLE1_RESU LT);


In the simple example that I constructed above I don't make any of the
API calls that you specified (createElement( ), createAttribute (),
.....). Let me know what else I can provide - I really appreciate the
help. I spent the better part of today trying to find info on why the
transformation isn't working correctly. I also forgot to mention that
the version of Xalan that is being used is 2.6.5.

Additionally I will try the code you posted above.

Feb 14 '06 #6
I just tried your code and it appears that it's a problem with using a
DOMSource vs. a StreamSource. I'm going to have to research why that is.

Feb 14 '06 #7
mjarends wrote:
xmlns="http://www.w3.org/Graphics/SVG/SVG-19990812.dtd"
Change the SVG namespace to xmlns="http://www.w3.org/2000/svg".
<xsl:output method="xml" indent="yes" media-type="image/svg"/>
The correct MIME type is "image/svg+xml".
<xsl:templat e match="/">


The rest works for me.

cu, Thomas
--
SVG - Learning By Coding
<http://svglbc.datenver drahten.de/>
Feb 14 '06 #8

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

Similar topics

6
2747
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a straight XML file http://www.discovertravelandtours.com/test/templates/test.xml?Location=Germany To another XML file http://www.discovertravelandtours.com/test/templates/test2.xml?Location=Germany
2
2117
by: Taare | last post by:
Hi, I got <xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD HTML 4.01//EN" doctype-system=" http://www.w3.org/TR/html4/strict.dtd"/> in my XSLT file. This should remove all XML related code and replace with HTML valid code, but with my commandline XSLT transformer(http://xmlsoft.org/XSLT/) it outputs a xmlns on elements I'v used <xsl:copy-of select="/some/node"> to produce. Is this how it should work, or is this...
4
1832
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
5
1466
by: dennis | last post by:
Hi, First of all, hi to you all. I'm working on a Delphi project wich is becoming near it's deadline. I have a very simple XSLT question wich i hope one of you folks can help me with? The problem is i need to transform a xml file from this: <root>
7
2869
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
4
1498
by: Lord0 | last post by:
Hi there, Is the following possible with XSLT? Given the following example XML docs: <!-- doc 1--> <user> <username>myUsername</username> <password></password> <phone>12345</phone>
3
9614
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the difference between two source documents and output node-sets which are "different" (changed or new) to new XML files using xsl:result-document To describe the problem I have provided some example data below along with my a portion of my current...
11
2091
by: =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post by:
Context: I'm trying to compare XML tree fragments and I'm doing so by outputting the attributes of each element in the tree and outputting it to a string then normalizing the strings. Then I'm doing a contains of the current string against the following-sibling::* to determine if we have duplicates. If we have a duplicate, we move to the next item, if there is no duplicate, we output the small tree. I'm hitting a completely ridiculous...
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
9628
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
9464
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
10292
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...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
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
6722
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();...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.