Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > problem with xslt transformation

Reply
Thread Tools

problem with xslt transformation

 
 
Pathik
Guest
Posts: n/a
 
      03-27-2007
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" xmlnssl="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

 
Reply With Quote
 
 
 
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      03-27-2007
* 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" xmlnssl="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 · (E-Mail Removed) · 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/
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      03-27-2007
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" xmlnssl="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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in xml transformation using xslt bosesuparna XML 0 11-25-2011 11:47 AM
Xpath and XSLT-transformation problem Pathik XML 1 03-30-2007 07:42 AM
Xslt Transformation getting &lt; and &gt; =?Utf-8?B?UGF0Qw==?= ASP .Net 2 05-19-2004 12:15 AM
XML file-- XSLT transformation problem with attributes of root element Wolfgang XML 2 04-09-2004 01:20 AM
XML file-- XSLT transformation problem with attributes of root element Wolfgang XML 0 04-06-2004 09:31 PM



Advertisments