Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mixed output

 
sanj singh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 395
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic