• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSL for-each and HR

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,
I am relatively new to XML so please pardon my ignorance in this matter.
I am trying to write a XSL stylesheet. I already have an XML document which I have to use with the XSL stylesheet. I have to extract some nodes of XML and put in a tabular format.
for example: I have a Term node, a student during his school year can have multiple terms. This info I have to put in tabular format. One term should have its own table and between two tables I need a hard rule (HTML TAG --> HR), however when I reach the LAST table I should not put a hard rule & so also I cannot put a hard rule before the start of the FIRST table.
I do not know what the logic to use. I am using the for-each loop.
Thanks in advance for your help!!!
-Amish
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's assume your document is
<student>
   <term>1</term>
   <term>2</term>
   <term>3</term>
</student>
You need to output <hr/> tag after each "term", except for the last one. To test this condition, you can use current() and last() functions, which return the current and the last position in a set of nodes defined in "select" clause of your <xsl:for-each> element. So it will be:
<xsl:template match="student">
   <xsl:for-each select="term">
       <xsl:value-of select="."/>
       <xsl:if test="not (current() = last())">
           <hr/>
       </xsl:if>
   </xsl:for-each>
</xsl:template>
the output:
1<hr/>2<hr/>3
[ February 21, 2002: Message edited by: Mapraputa Is ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried doing that but it does not work, this is what I have

It still gives me a hr after the LAST Table.
Thanks in advance for ur help.
-Amish
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops, sorry, it should be
<xsl:if test="not (position()=last())">
not
<xsl:if test="not (current()=last())">
[ February 22, 2002: Message edited by: Mapraputa Is ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mapraputa Is:
Oops, sorry, it should be
<xsl:if test="not (position()=last())">
not
<xsl:if test="not (current()=last())">
[ February 22, 2002: Message edited by: Mapraputa Is ]


Thank you very much Mapraputa for your help. It works like a charm!!!
reply
    Bookmark Topic Watch Topic
  • New Topic