XSL For-Each Question

Discussion in 'XML' started by darin dimitrov, Oct 18, 2004.

  1. I have a XML file with a structure summarized below.

    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="transform.xsl"?>
    <ns0:root xmlns:ns0="http://po">
    <products>
    <ns1:product xmlns:ns1="http://ns1">
    <name>Product A</name>
    </ns1:product>
    <ns2:product xmlns:ns2="http://ns2">
    <name>Product B</name>
    </ns2:product>
    </products>
    </ns0:root>

    I would like to apply a XSL transformation on this document which
    will iterate through all the *product* nodes and will output the value
    of the *name* sub-node. The problem is that there is a namespace on
    the *product* node which I cannot remove (the structure of the XML
    document cannot be changed). Is there a possibility to perform this
    using the for-each attribute and probably some well formed XPath
    expressions? I am new to XSL, so I would appreciate any suggestions.

    Thanks,

    Darin
    darin dimitrov, Oct 18, 2004
    #1
    1. Advertising

  2. darin dimitrov wrote:

    > I have a XML file with a structure summarized below.
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <?xml-stylesheet type="text/xsl" href="transform.xsl"?>
    > <ns0:root xmlns:ns0="http://po">
    > <products>
    > <ns1:product xmlns:ns1="http://ns1">
    > <name>Product A</name>
    > </ns1:product>
    > <ns2:product xmlns:ns2="http://ns2">
    > <name>Product B</name>
    > </ns2:product>
    > </products>
    > </ns0:root>
    >
    > I would like to apply a XSL transformation on this document which
    > will iterate through all the *product* nodes and will output the value
    > of the *name* sub-node. The problem is that there is a namespace on
    > the *product* node which I cannot remove (the structure of the XML
    > document cannot be changed). Is there a possibility to perform this
    > using the for-each attribute and probably some well formed XPath
    > expressions?


    <xsl:for-each select="*[local-name() = 'product']">

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 18, 2004
    #2
    1. Advertising

  3. A desired result would be:

    <table>
    <tr>
    <td>Product A</td>
    </tr>
    <tr>
    <td>Product B</td>
    </tr>
    </table>

    Anyway I found that using the following xsl would work:

    <table>
    <xsl:for-each select="//products/child::*">
    <tr>
    <td><xsl:value-of select="name"/></td>
    </tr>
    </xsl:for-each>
    </table>
    darin dimitrov, Oct 18, 2004
    #3
    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. John Blair
    Replies:
    1
    Views:
    409
    Eliyahu Goldin
    Aug 3, 2005
  2. Sparko
    Replies:
    0
    Views:
    409
    Sparko
    Jul 9, 2004
  3. Tjerk Wolterink

    xsl:for-each for each 3 elements problem

    Tjerk Wolterink, Nov 3, 2004, in forum: XML
    Replies:
    3
    Views:
    426
    Tjerk Wolterink
    Nov 3, 2004
  4. Replies:
    1
    Views:
    3,598
    A. Bolmarcich
    May 27, 2005
  5. Red
    Replies:
    2
    Views:
    1,216
    Pavel Lepin
    May 9, 2007
Loading...

Share This Page