aspose file tools*
The moose likes XML and Related Technologies and the fly likes mixed output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "mixed output" Watch "mixed output" New topic
Author

mixed output

sanj singh
Ranch Hand

Joined: Jun 30, 2001
Posts: 129
Hi All
here is my xml file(order.xml)
<?xml version="1.0"?>
<order number="312597">
<date>2000/1/1</date>
<customer id="216A">Company A</customer>
<item>
<part-number warehouse="warehouse 11">E16-25A</part-number>
<description>Production class Widget</description>
<quantity>16</quantity>
</item>
</order>

and here is my xsl file(order.xsl)
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="customer[@id]">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>

I just want to print the name of the customer but the out I am getting is this

<?xml version="1.0" encoding="utf-8"?>
2000/1/1
Company A

E16-25A
Production class Widget
16

Can anybody help me please?
regards
sanj
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi,
Here is the XSL code.
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="order[customer[@id]]">
<xsl:value-of select="/order/customer"/>
</xsl:template>
</xsl:stylesheet>

Thanks.

------------------
L Goundalkar
lggoundalkar@hotmail.com
Sun Certified Programmer for Java 2 Platform


SCJP, SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Sanj,
The default templates are displaying the text of all nodes in the ouptput. So, in your case, it means you have to desactivate this behaviour. If you also wish to avoid having the <?xml?> declaration at the top, specify that you want to output text.
Your code should now look like this:

For information, the predefined templates (built-in) are the following:

Hope this helps.
Best luck,
Beno�t
PS: Goundalkar's suggestion is not best-practice as it prevents extensibility of your stylesheet. Prefer small templates with minimum matching.
[This message has been edited by Beno�t d'Oncieu (edited September 04, 2001).]
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi Beno�t,
I agree with you. Thanks.
BTW can you please expail the xsl file which you have written.
I think <xsl utput method="text"/> is not necessary.
Also Can you please go through the xsl elements and expail exactly what its doing.
Thanks.

------------------
L Goundalkar
lggoundalkar@hotmail.com
Sun Certified Programmer for Java 2 Platform
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi L,
The stylesheet I've written only uses basic XSLT constructs. Anyway concerning the <xmlutput/> element. It allows you to output non valid XML and more especially text without output escaping. Furthermore, it does not output the XML declaration (<?xml version="1.0"?> ).
Another way to prevent the XML declaration is to use this form:
<xmlutput omit-xml-declaration="yes">
To learn more about XSLT, you will find a lot of tutorials on the Web ( http://www.google.com/search?q=XSLT+tutorial ).
You can also bookmark the W3C recommendation at:
http://www.w3.org/TR/xslt
Cheers,
Beno�t
[This message has been edited by Beno�t d'Oncieu (edited September 04, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mixed output