You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Sanjay Gupta <sa...@cisco.com> on 2002/08/29 02:51:13 UTC

XSL- for each question

I am trying to write xsl that traverses an xml and prints node name and node
value in a tabular format.
How can I use xsl:for-each tag to traverse through each node in an element
and print node name - node value pair? How do I find the name of the node?
e.g.
<student>
<name> John</name>
<gender>Male</gender>
</student>

I want the output to be -
<table>
<tr><td>name</td><td>John</td></tr>
<tr><td>gender</td><td>Male</td></tr>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="rbml">
  <html xmlns="http://www.w3.org/1999/xhtml">
   <body>
    <xsl:for-each>
      How to find node name & node value.
    </xsl:for-each>
   </body>
  </html>
</xsl:stylesheet>
-Sanjay


Re: XSL- for each question

Posted by "Frank E. Weiss" <fr...@well.com>.
Sanjay,

Essential for using XSLT:

http://www.w3.org/TR/xpath

Download it and keep a shortcut handy.

-- Frank Weiss

Sanjay Gupta wrote:

> Thanks. It works! Where could I get a list of fuctions like local-name()? I
> looked into many xml books but couldn't find this function.
>
> Regards,
> -sanjay
>
> -----Original Message-----
> From: Kai Ojansuu [mailto:clapu@pori.tut.fi]
> Sent: Wednesday, August 28, 2002 11:32 PM
> To: Sanjay Gupta
> Cc: xalan-j-users@xml.apache.org
> Subject: Re: XSL- for each question
>
> Try something like:
>
> <h1>Student list</h1>
> <table>
>  <xsl:for-each select="student">
>   <xsl:for-each select="*">
>    <tr>
>      <td><xsl:value-of select="local-name(.)"/></td>
>      <td><xsl:value-of select="."/></td>
>    </tr>
>   </xsl:for-each>
>  </xsl:for-each>
> </table>
> _____________
> name   |john
> gender |male
> name   |jack
> gender |male
> ...
>
> On Wed, 28 Aug 2002, Sanjay Gupta wrote:
>
> > I am trying to write xsl that traverses an xml and prints node name and
> node
> > value in a tabular format.
> > How can I use xsl:for-each tag to traverse through each node in an element
> > and print node name - node value pair? How do I find the name of the node?
> > e.g.
> > <student>
> > <name> John</name>
> > <gender>Male</gender>
> > </student>
> >
> > I want the output to be -
> > <table>
> > <tr><td>name</td><td>John</td></tr>
> > <tr><td>gender</td><td>Male</td></tr>
> >
> > <xsl:stylesheet version="1.0"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> >  <xsl:template match="rbml">
> >   <html xmlns="http://www.w3.org/1999/xhtml">
> >    <body>
> >     <xsl:for-each>
> >       How to find node name & node value.
> >     </xsl:for-each>
> >    </body>
> >   </html>
> > </xsl:stylesheet>
> > -Sanjay
> >
> >


RE: XSL- for each question

Posted by Sanjay Gupta <sa...@cisco.com>.
Thanks. It works! Where could I get a list of fuctions like local-name()? I
looked into many xml books but couldn't find this function.

Regards,
-sanjay

-----Original Message-----
From: Kai Ojansuu [mailto:clapu@pori.tut.fi]
Sent: Wednesday, August 28, 2002 11:32 PM
To: Sanjay Gupta
Cc: xalan-j-users@xml.apache.org
Subject: Re: XSL- for each question


Try something like:

<h1>Student list</h1>
<table>
 <xsl:for-each select="student">
  <xsl:for-each select="*">
   <tr>
     <td><xsl:value-of select="local-name(.)"/></td>
     <td><xsl:value-of select="."/></td>
   </tr>
  </xsl:for-each>
 </xsl:for-each>
</table>
_____________
name   |john
gender |male
name   |jack
gender |male
...


On Wed, 28 Aug 2002, Sanjay Gupta wrote:

> I am trying to write xsl that traverses an xml and prints node name and
node
> value in a tabular format.
> How can I use xsl:for-each tag to traverse through each node in an element
> and print node name - node value pair? How do I find the name of the node?
> e.g.
> <student>
> <name> John</name>
> <gender>Male</gender>
> </student>
>
> I want the output to be -
> <table>
> <tr><td>name</td><td>John</td></tr>
> <tr><td>gender</td><td>Male</td></tr>
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>  <xsl:template match="rbml">
>   <html xmlns="http://www.w3.org/1999/xhtml">
>    <body>
>     <xsl:for-each>
>       How to find node name & node value.
>     </xsl:for-each>
>    </body>
>   </html>
> </xsl:stylesheet>
> -Sanjay
>
>



Re: XSL- for each question

Posted by Kai Ojansuu <cl...@pori.tut.fi>.
Try something like:

<h1>Student list</h1>
<table>
 <xsl:for-each select="student">
  <xsl:for-each select="*">
   <tr>
     <td><xsl:value-of select="local-name(.)"/></td>
     <td><xsl:value-of select="."/></td>
   </tr>
  </xsl:for-each>
 </xsl:for-each>
</table>
_____________
name   |john
gender |male
name   |jack
gender |male
...


On Wed, 28 Aug 2002, Sanjay Gupta wrote:

> I am trying to write xsl that traverses an xml and prints node name and node
> value in a tabular format.
> How can I use xsl:for-each tag to traverse through each node in an element
> and print node name - node value pair? How do I find the name of the node?
> e.g.
> <student>
> <name> John</name>
> <gender>Male</gender>
> </student>
> 
> I want the output to be -
> <table>
> <tr><td>name</td><td>John</td></tr>
> <tr><td>gender</td><td>Male</td></tr>
> 
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>  <xsl:template match="rbml">
>   <html xmlns="http://www.w3.org/1999/xhtml">
>    <body>
>     <xsl:for-each>
>       How to find node name & node value.
>     </xsl:for-each>
>    </body>
>   </html>
> </xsl:stylesheet>
> -Sanjay
> 
>