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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

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

    On Apr 4, 4:37 am, Martin Honnen <mahotr...@yaho o.dewrote:
    Lee wrote:
    <ProductSearc h xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:yaho o:aprods" xsi:schemaLocat ion="urn:yahoo: aprods
    http://api.shopping.ya hoo.com/shoppingservice/v2/aproductsearch. xsd">
    ............... ...
    </ProductSearch>
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    >
    Add
    xmlns:ap="urn:y ahoo:aprods"
    on the xsl:stylesheet element, then use the prefix 'ap' in your XPath
    expressions e.g.
    >
    <xsl:for-each select="Product Search/
    Products/Product">
    >
    <xsl:for-each select="ap:Prod uctSearch/ap:Products/ap:Product">
    >
    <xsl:value-of
    select="Catalog/PriceFrom"/>
    >
    <xsl:value-of select="ap:Cata log/ap:PriceForm">
    >
    <xsl:value-of
    select="Catalog/PriceTo"/>
    >
    <xsl:value-of select="ap:Cata log/ap:PriceTo"/>
    >
    --
    >
    Martin Honnen
    http://JavaScript.FAQTs.com/
    Thanks a lot, it works fine now. thanks for the help.

    Leave a comment:


  • Martin Honnen
    Guest replied
    Re: xslt not working when xml has xmlns=&quot;urn &quot; in root element.

    Lee wrote:
    <ProductSearc h xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:yaho o:aprods" xsi:schemaLocat ion="urn:yahoo: aprods
    http://api.shopping.ya hoo.com/shoppingservice/v2/aproductsearch. xsd">
    ............... ...
    </ProductSearch>
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    Add
    xmlns:ap="urn:y ahoo:aprods"
    on the xsl:stylesheet element, then use the prefix 'ap' in your XPath
    expressions e.g.
    <xsl:for-each select="Product Search/
    Products/Product">
    <xsl:for-each select="ap:Prod uctSearch/ap:Products/ap:Product">
    <xsl:value-of
    select="Catalog/PriceFrom"/>
    <xsl:value-of select="ap:Cata log/ap:PriceForm">
    <xsl:value-of
    select="Catalog/PriceTo"/>
    <xsl:value-of select="ap:Cata log/ap:PriceTo"/>


    --

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

    Leave a comment:


  • p.lepin@ctncorp.com
    Guest replied
    Re: xslt not working when xml has xmlns=&quot;urn &quot; in root element.

    On Apr 3, 9:09 pm, "Lee" <lee.jenkins... @gmail.comwrote :
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl"
    href="aproducts earch.xslt"?>
    <ProductSearc h
    xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:yaho o:aprods"
    xsi:schemaLocat ion=
    "urn:yahoo:apro dshttp://api.shopping.ya hoo.com/shoppingservice/v2/aproductsearch. xsd">
    ............... ...
    </ProductSearch>
    >
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="utf-8"
    omit-xml-declaration="ye s" indent="yes"/>
    <xsl:template match="/">
    <HTML>
    <BODY>
    <TABLE BORDER="2">
    <TR>
    <TD>From</TD>
    <TD>To</TD>
    </TR>
    <xsl:for-each
    select="Product Search/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:yaho o: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:apro ds}ProductSearc h, 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

    Leave a comment:


  • Lee
    Guest started a topic xslt not working when xml has xmlns="urn" in root element.

    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="aproducts earch.xslt"?>
    <ProductSearc h xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
    xmlns="urn:yaho o:aprods" xsi:schemaLocat ion="urn:yahoo: aprods
    http://api.shopping.ya hoo.com/shoppingservice/v2/aproductsearch. xsd">
    ............... ....
    </ProductSearch>


    I am testing my xslt file:


    <?xml version="1.0" encoding="utf-8"?>
    <xsl:styleshe et version="1.0"
    xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" encoding="utf-8" omit-xml-
    declaration="ye s"
    indent="yes"/>


    <xsl:template match="/">
    <HTML>
    <BODY>
    <TABLE BORDER="2">
    <TR>
    <TD>From</TD>
    <TD>To</TD>
    </TR>
    <xsl:for-each select="Product Search/
    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:yaho o: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!

Working...