Re: [xsl] Re: xsl-list Digest 22 Mar 2005 06:10:01 -0000 Issue 364

Subject: Re: [xsl] Re: xsl-list Digest 22 Mar 2005 06:10:01 -0000 Issue 364
From: "Joe Fawcett" <joefawcett@xxxxxxxxxxx>
Date: Tue, 22 Mar 2005 15:39:18 -0000
----- Original Message ----- From: "Kumar S" <kumar.subscriptions@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, March 22, 2005 2:59 PM
Subject: [xsl] Re: xsl-list Digest 22 Mar 2005 06:10:01 -0000 Issue 364



Hi Friends,
I'm having an xml as follows
       <webapps>
         <applications>
           <application>
               <name>Application1</name>
               <id>1</id>
               <users>
                   <user>
                       <name>Arjun</name>
                       <accessrestrictions>some text</accessrestrictions>
                   </user>
                   <user>
                       <name>user2</name>
                       <accessrestrictions>some text</accessrestrictions>
                   </user>
                   <user>
                       <name>user3</name>
                       <accessrestrictions>some text</accessrestrictions>
                   </user>
                   <user>
                       <name>user4</name>
                       <accessrestrictions>some text</accessrestrictions>
                   </user>
               </users>
           </application>
           <application>
    <name>Application2</name>
    <id>2</id>
    <users>
<user>
    <name>arjun</name>
    <accessrestrictions>some text</accessrestrictions>
</user>
<user>
    <name>sruthi</name>
    <accessrestrictions>some text</accessrestrictions>
</user>
    </users>
           </application>
         </applications>
</webapps>

I'm trying to list the name,id and then all the users for the
application using xsl
<xsl:for-each select="webapps/applications/application">
   <xsl:variable name="curid" select="id" />
   <xsl:for-each select="webapps/applications/application/users/user">
     <xsl:value-of select="$curid" />
     <xsl:value-of select="name" />
     <xsl:value-of select="accessrestrictions" />
   </xsl:for-each>
</xsl:for-each>

But the above code does not work. can anybody help me.

Thanks in advance,
Kumar S

I'd normally suggets this link as this is a sort of grouping problem:

http://www.jenitennison.com/xslt/grouping/muenchian.html

but as the information is already grouped and sorted something like this might do:

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="text"/>

<xsl:template match="/">

<xsl:apply-templates select="webapps/applications/application"/>

</xsl:template>


<xsl:template match="application">


<xsl:text>Name: </xsl:text><xsl:value-of select="name"/><xsl:text> (</xsl:text><xsl:value-of select="id"/><xsl:text>)&#xa;</xsl:text>

<xsl:apply-templates select="users/user"/>

</xsl:template>


<xsl:template match="user">


<xsl:text>&#x9;</xsl:text><xsl:value-of select="name"/><xsl:text>: </xsl:text><xsl:value-of select="accessrestrictions"/><xsl:text>&#xa;</xsl:text>

</xsl:template>

</xsl:stylesheet>



Joe

Current Thread