469,627 Members | 953 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,627 developers. It's quick & easy.

problem with xslt transformation

Hi All,

I am New to xml. Currently I am trying to transform one xml file to
another file using xslt

my xml file is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xml" href="test.xsl" version="2.0"?>
<Data>
<Header>
<ID>JD014</ID>
<Test>true</Test>
</Header>
</Data>

and xsl file is as follows:test.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:template match="/">
<xsl:for-each select="Header">
<xsl:value-of select="ID"></xsl:value-of>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

I m trying to print the value of ID in output . But instead of
transformation Internet explorer simply
shows input file as it is.

Please check this and let me know where i am wrong.

Thanks and Regards,
Pathik

Mar 27 '07 #1
2 1885
* Pathik wrote in comp.text.xml:
>Hi All,

I am New to xml. Currently I am trying to transform one xml file to
another file using xslt

my xml file is as follows:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xml" href="test.xsl" version="2.0"?>
<Data>
<Header>
<ID>JD014</ID>
<Test>true</Test>
</Header>
</Data>

and xsl file is as follows:test.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:template match="/">
<xsl:for-each select="Header">
<xsl:value-of select="ID"></xsl:value-of>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

I m trying to print the value of ID in output . But instead of
transformation Internet explorer simply
shows input file as it is.
Internet Explorer does not support XSLT 2.0 and the xml-stylesheet
processing instruction does not have a version pseudo-attribute.
Further, <xsl:template match="/"matches the document node, not
the root element node, so your for-each would select no nodes as
there are no "Header" elements that are children of the document
node.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Mar 27 '07 #2
Pathik wrote:
<Data>
<Header>
<ID>JD014</ID>
<Test>true</Test>
</Header>
</Data>

and xsl file is as follows:test.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
^^^^^^^^^^^^^
Use version="1.0" for IE or other browsers as XSLT 2.0 is too new to be
supported by browsers. While the XSLT processor will try to process the
stylesheet even for a not supported version (so called forwards
compatible processsing <http://www.w3.org/TR/xslt#forwards>) you do not
help yourself understanding normal XSLT transformation if you run
stylesheet that way.
Transform">
<xsl:template match="/">
Inside a browser you usually want to transform XML to HTML so best
practice is to include the necessary elements making up a HTML document e.g.
<html>
<head>
<title>XSLT test</title>
</head>
<body>
<xsl:for-each select="Header">
The Header element is a child of the Data element so you need
<xsl:for-each select="Data/Header>
<xsl:value-of select="ID"></xsl:value-of>
</xsl:for-each>
</body>
</html>
</xsl:template>


--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 27 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Collin VanDyck | last post: by
4 posts views Thread by Stephen | last post: by
5 posts views Thread by shauldar | last post: by
6 posts views Thread by JJBean | last post: by
8 posts views Thread by Demon News | last post: by
reply views Thread by Thomas H. | last post: by
5 posts views Thread by crazydiode | last post: by
4 posts views Thread by simon.a.hulbert | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.