problem with xslt transformation

P

Pathik

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
 
B

Bjoern Hoehrmann

* 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.
 
M

Martin Honnen

Pathik said:
<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>
said:
<xsl:for-each select="Header">

The Header element is a child of the Data element so you need
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top