XSL For-Each Question

D

darin dimitrov

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
 
M

Martin Honnen

darin said:
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']">
 
D

darin dimitrov

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top