Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSL For-Each Question

Reply
Thread Tools

XSL For-Each Question

 
 
darin dimitrov
Guest
Posts: n/a
 
      10-18-2004
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>
<ns1roduct xmlns:ns1="http://ns1">
<name>Product A</name>
</ns1roduct>
<ns2roduct xmlns:ns2="http://ns2">
<name>Product B</name>
</ns2roduct>
</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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-18-2004


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>
> <ns1roduct xmlns:ns1="http://ns1">
> <name>Product A</name>
> </ns1roduct>
> <ns2roduct xmlns:ns2="http://ns2">
> <name>Product B</name>
> </ns2roduct>
> </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/
 
Reply With Quote
 
 
 
 
darin dimitrov
Guest
Posts: n/a
 
      10-18-2004
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>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
XSLT question related to <xsl:template> and <xsl:apply-templates> Vijay singh XML 1 11-04-2004 03:42 PM
XSL-1000: (Fatal Error) Error while parsing XSL file (org.apache.xerces.parsers.AbstractSAXParser$AttributesProxy) Kevin Flood Java 1 09-13-2004 02:28 PM
XSL-1000: (Fatal Error) Error while parsing XSL file (org.apache.xerces.parsers.AbstractSAXParser$AttributesProxy) Kevin Flood Java 0 09-08-2004 02:11 PM
Three question which is not yet answered clearly and correct so far !! challenging question in xsl and also in xsl fo Philip Meyer XML 0 11-30-2003 04:42 PM



Advertisments