xsl-list
[Top] [All Lists]

RE: question about a non-trivial apply-templates

2003-12-04 16:05:36
Try this:

<?xml version="1.0"?>
<xsl:stylesheet 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
        version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
        <xsl:for-each select="/rowset/row/field3[not(.=preceding::field3)]">
        sector <xsl:value-of select="."/> 
                <xsl:for-each select="/rowset/row[field3=current()]">
                        row <xsl:value-of select="position()"/>
                                        label1 = value1
                                        label2 = value2</xsl:for-each>
                <xsl:text>
</xsl:text>
                </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Josh

-----Original Message-----
From: Jaime A Stuardo Bahamondes [mailto:jstuardo(_at_)security(_dot_)cl]
Sent: Thursday, December 04, 2003 2:45 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] question about a non-trivial apply-templates


Hi all..

How can I this? 

I have an XML, for example,

<rowset>
  <row>
    <field1>....</field1>
    <field2>....</field2>
    <field3>1</field3>
  </row>
  <row>
    <field1>....</field1>
    <field2>....</field2>
    <field3>1</field3>
  </row>
  <row>
    <field1>....</field1>
    <field2>....</field2>
    <field3>2</field3>
  </row>
  <row>
    <field1>....</field1>
    <field2>....</field2>
    <field3>2</field3>
  </row>
  <row>
    <field1>....</field1>
    <field2>....</field2>
    <field3>3</field3>
  </row>
  <row>
    <field1>....</field1>
    <field2>....</field2>
    <field3>3</field3>
  </row>
</rowset>

Notice the value of field3 in each <row>.

I want to program an XSL that generates an HTML page that has 3 separate 
sectors, one for each value of field3. Each sector has exactly the same 
structure, more or less this way:

sector 1 (when field3 evaluates to 1)
   row1
     label1 = value1
     label2 = value2
   row2
     label1 = value1
     label2 = value1
<blank space>
sector 2 (when field3 evaluates to 2)
   row1
     label1 = value1
     label2 = value2
   row2
     label1 = value1
     label2 = value1
<blank space>
sector 3 (when field3 evaluates to 3)
   row1
     label1 = value1
     label2 = value2
   row2
     label1 = value1
     label2 = value1


I could do it if I generate an XML with the 3 sectors separately and calling 
apply templates for each, but in this case, that XML is built by mean of an 
Oracle query, so I cannot modify it.

Any help?
Thanks a lot in advance

Jaime

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>