Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


position() within nested xsl:for-each

From: Grinder <grinder@--.----.----.--->
To: NULL
Date: 8/4/2005 8:17:00 PM
This is a multi-part message in MIME format.
--------------070702070006090600050701
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

My apologies for asking what must be a relatively common question, but I 
have been unsuccessful in finding it discussed elsewhere -- likely 
because I'm not using the right search terms.

Given XML of the form:

<Season>
   <Episode>
     <Title>First show of first season</Title>
   </Episode>
   <Episode>
     <Title>Second show of first season</Title>
   </Episode>
   <Episode>
     <Title>Third show of first season</Title>
   </Episode>
</Season>
<Season>
   <Episode>
     <Title>First show of second season</Title>
   </Episode>
   <Episode>
     <Title>Second show of second season</Title>
   </Episode>
</Season>


And XSL like this:

<xsl:for-each select="Season">
   <xsl:for-each select="Episode">

     <xsl:value-of select="position()"/>
     <xsl:text>. </xsl:text>
     <xsl:value-of select="Title"/>
     <br/>

   </xsl:for-each>
</xsl:for-each>

Which yields output like this:

1. First show of first season
2. Second show of first season
3. Third show of first season
1. First show of second season
2. Second show of second season

How can I get the numbering to be relative to the entire document, 
instead of the <Season>, like this:

1. First show of first season
2. Second show of first season
3. Third show of first season
4. First show of second season
5. Second show of second season

Thanks for your time and consideration.

--------------070702070006090600050701
Content-Type: text/xml;
 name="test.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="test.xml"

<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type='text/xsl' href='test.xsl'?>
<EpisodeGuide>
  <Season>
    <Episode>
      <Title>First show of first season</Title>
    </Episode>
    <Episode>
      <Title>Second show of first season</Title>
    </Episode>
    <Episode>
      <Title>Third show of first season</Title>
    </Episode>
  </Season>
  <Season>
    <Episode>
      <Title>First show of second season</Title>
    </Episode>
    <Episode>
      <Title>Second show of second season</Title>
    </Episode>
  </Season>
</EpisodeGuide>

--------------070702070006090600050701
Content-Type: text/xml;
 name="test.xsl"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
 filename="test.xsl"

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
  <xsl:output method="html"/>
  <xsl:template match="/EpisodeGuide">
    <html>
      <body>

      <xsl:for-each select="Season">
        <xsl:for-each select="Episode">

          <xsl:value-of select="position()"/>
          <xsl:text>. </xsl:text>
          <xsl:value-of select="Title"/>
          <br/>

        </xsl:for-each>
      </xsl:for-each>

      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

--------------070702070006090600050701--


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent