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

Discussion in 'XML' started by Lee, Apr 3, 2007.

  1. Lee

    Lee Guest

    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:eek:utput 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!
    Lee, Apr 3, 2007
    #1
    1. Advertising

  2. Lee

    Guest

    On Apr 3, 9:09 pm, "Lee" <> 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:eek:utput 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
    , Apr 4, 2007
    #2
    1. Advertising

  3. 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/
    Martin Honnen, Apr 4, 2007
    #3
  4. Lee

    Lee Guest

    On Apr 4, 4:37 am, Martin Honnen <> 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.
    Lee, Apr 4, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Philippe Poulard

    [XUS] An XML URN Scheme

    Philippe Poulard, Feb 25, 2005, in forum: XML
    Replies:
    0
    Views:
    517
    Philippe Poulard
    Feb 25, 2005
  2. Philippe Poulard
    Replies:
    0
    Views:
    431
    Philippe Poulard
    Feb 25, 2005
  3. Replies:
    0
    Views:
    1,325
  4. Rajesh
    Replies:
    0
    Views:
    380
    Rajesh
    Jul 18, 2006
  5. afshar
    Replies:
    3
    Views:
    24,160
    aljar
    May 19, 2010
Loading...

Share This Page