Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xslt not working when xml has xmlns="urn" in root element.

Reply
Thread Tools

xslt not working when xml has xmlns="urn" in root element.

 
 
Lee
Guest
Posts: n/a
 
      04-03-2007
Hello guys, I am new to XML and working on a XSLT to transforn yahoo
shopping search result to html. my problem is the return XML contain
xmlns in root element, here is the sample xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="aproductsearch.xslt"?>
<ProductSearch xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:yahoo:aprods" xsi:schemaLocation="urn:yahoo:aprods
http://api.shopping.yahoo.com/shoppingservice/v2/aproductsearch.xsd">
...................
</ProductSearch>


I am testing my xslt file:


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="html" encoding="utf-8" omit-xml-
declaration="yes"
indent="yes"/>


<xsl:template match="/">
<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD>From</TD>
<TD>To</TD>
</TR>
<xsl:for-each select="ProductSearch/
Products/Product">
<TR>
<TD>
<xsl:value-of
select="Catalog/PriceFrom"/>
</TD>
<TD>
<xsl:value-of
select="Catalog/PriceTo"/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
</BODY>
</HTML>
</xsl:template>


</xsl:stylesheet>


if I remove the xmlns="urn:yahoo:aprods" from the XML, then the xslt
works fine, otherwise, nothing shows up. I don't know what is the
problem of my xslt file.


Thanks a lot!

 
Reply With Quote
 
 
 
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      04-04-2007
On Apr 3, 9:09 pm, "Lee" <(E-Mail Removed)> wrote:
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet type="text/xsl"
> href="aproductsearch.xslt"?>
> <ProductSearch
> xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="urn:yahoo:aprods"
> xsi:schemaLocation=
> "urn:yahoo:aprodshttp://api.shopping.yahoo.com/shoppingservice/v2/aproductsearch.xsd">
> ..................
> </ProductSearch>
>
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet version="1.0"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">
> <xslutput method="html" encoding="utf-8"
> omit-xml-declaration="yes" indent="yes"/>
> <xsl:template match="/">
> <HTML>
> <BODY>
> <TABLE BORDER="2">
> <TR>
> <TD>From</TD>
> <TD>To</TD>
> </TR>
> <xsl:for-each
> select="ProductSearch/Products/Product">
> <TR>
> <TD>
> <xsl:value-of select="Catalog/PriceFrom"/>
> </TD>
> <TD>
> <xsl:value-of select="Catalog/PriceTo"/>
> </TD>
> </TR>
> </xsl:for-each>
> </TABLE>
> </BODY>
> </HTML>
> </xsl:template>
> </xsl:stylesheet>


Using tabs or 8 spaces for indentation on the usenet is not
particularly wise.

> if I remove the xmlns="urn:yahoo:aprods" from the XML,
> then the xslt works fine, otherwise, nothing shows up. I
> don't know what is the problem of my xslt file.


What did you expect? ProductSearch element in the XML
document you've provided is really
{urn:yahoo:aprods}ProductSearch, and you're selecting
{}ProductSearch elements in your for-each. Consider reading
some introductory material on XML Namespaces overall and on
using XML Namespaces in XSL Transformations in particular.

--
Pavel Lepin

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-04-2007
Lee wrote:

> <ProductSearch xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="urn:yahoo:aprods" xsi:schemaLocation="urn:yahoo:aprods
> http://api.shopping.yahoo.com/shoppingservice/v2/aproductsearch.xsd">
> ..................
> </ProductSearch>


> <xsl:stylesheet version="1.0"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">


Add
xmlns:ap="urn:yahoo:aprods"
on the xsl:stylesheet element, then use the prefix 'ap' in your XPath
expressions e.g.

> <xsl:for-each select="ProductSearch/
> Products/Product">


<xsl:for-each select="aproductSearch/aproducts/aproduct">

> <xsl:value-of
> select="Catalog/PriceFrom"/>


<xsl:value-of select="ap:Catalog/apriceForm">

> <xsl:value-of
> select="Catalog/PriceTo"/>


<xsl:value-of select="ap:Catalog/apriceTo"/>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      04-04-2007
On Apr 4, 4:37 am, Martin Honnen <(E-Mail Removed)> wrote:
> Lee wrote:
> > <ProductSearch xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> > xmlns="urn:yahoo:aprods" xsi:schemaLocation="urn:yahoo:aprods
> >http://api.shopping.yahoo.com/shoppingservice/v2/aproductsearch.xsd">
> > ..................
> > </ProductSearch>
> > <xsl:stylesheet version="1.0"
> > xmlnssl="http://www.w3.org/1999/XSL/Transform">

>
> Add
> xmlns:ap="urn:yahoo:aprods"
> on the xsl:stylesheet element, then use the prefix 'ap' in your XPath
> expressions e.g.
>
> > <xsl:for-each select="ProductSearch/
> > Products/Product">

>
> <xsl:for-each select="aproductSearch/aproducts/aproduct">
>
> > <xsl:value-of
> > select="Catalog/PriceFrom"/>

>
> <xsl:value-of select="ap:Catalog/apriceForm">
>
> > <xsl:value-of
> > select="Catalog/PriceTo"/>

>
> <xsl:value-of select="ap:Catalog/apriceTo"/>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/


Thanks a lot, it works fine now. thanks for the help.

 
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
WSE 2.0 SP3 DIME client error: Response is not well-formed XML. ---> System.Xml.XmlException: Root element is missing. Rich Fowler ASP .Net Web Services 2 01-22-2010 03:31 PM
Query regarding XSLT "Root element not set" Amit Jain Java 4 07-23-2009 04:08 AM
SRT DIvision, Square root and reciprocal square root alghazo@siu.edu VHDL 0 05-27-2004 06:23 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