Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   xslt not working when xml has xmlns="urn" in root element. (http://www.velocityreviews.com/forums/t496211-xslt-not-working-when-xml-has-xmlns-urn-in-root-element.html)

Lee 04-03-2007 06:09 PM

xslt not working when xml has xmlns="urn" in root element.
 
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 xmlns:xsi="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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output 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!


p.lepin@ctncorp.com 04-04-2007 07:54 AM

Re: xslt not working when xml has xmlns="urn" in root element.
 
On Apr 3, 9:09 pm, "Lee" <lee.jenkins...@gmail.com> wrote:
> <?xml version="1.0" encoding="UTF-8"?>
> <?xml-stylesheet type="text/xsl"
> href="aproductsearch.xslt"?>
> <ProductSearch
> xmlns:xsi="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"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output 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


Martin Honnen 04-04-2007 11:37 AM

Re: xslt not working when xml has xmlns="urn" in root element.
 
Lee wrote:

> <ProductSearch xmlns:xsi="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"
> xmlns:xsl="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="ap:ProductSearch/ap:Products/ap:Product">

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


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

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


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


--

Martin Honnen
http://JavaScript.FAQTs.com/

Lee 04-04-2007 06:07 PM

Re: xslt not working when xml has xmlns="urn" in root element.
 
On Apr 4, 4:37 am, Martin Honnen <mahotr...@yahoo.de> wrote:
> Lee wrote:
> > <ProductSearch xmlns:xsi="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"
> > xmlns:xsl="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="ap:ProductSearch/ap:Products/ap:Product">
>
> > <xsl:value-of
> > select="Catalog/PriceFrom"/>

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

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


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



All times are GMT. The time now is 02:33 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57