RE: [xsl] Grouping by an attribute of a child

Subject: RE: [xsl] Grouping by an attribute of a child
From: David Christiansen <DavidCh@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 14 Apr 2003 08:05:58 -0600
OK.

I have an XML document that has a section called Activity.  Each activity
has an option of having attributes (which are defined in a database).  The
attribute will have a name and a value.  Thus a couple tables as such:

table Activity has fields ActivityID, ActivityDate (and many others)

Table Attribute has fields AttributeID, ActivityID, AttributeName, and
AttributeValue (OK, it is not exactly like this in our database, the
AttributeName is stored elsewhere to prevent data duplication, but for the
purposes of this example, this will work)


These are output into an XML as such (ignoring the parent nodes)
<Activity>
  <ActivityDate>
    {ActivityDate}
  </ActivityDate>
  <Attribute ID="{AttributeID}" Name="{AttributeName}"
Value="{AttributeValue}">
  <Attribute ID="{AttributeID}" Name="{AttributeName}"
Value="{AttributeValue}">
  <Attribute ID="{AttributeID}" Name="{AttributeName}"
Value="{AttributeValue}">
</Activity>
<Activity>
  <ActivityDate>
    {ActivityDate}
  </ActivityDate>
  <Attribute ID="{AttributeID}" Name="{AttributeName}"
Value="{AttributeValue}">
  <Attribute ID="{AttributeID}" Name="{AttributeName}"
Value="{AttributeValue}">
  <Attribute ID="{AttributeID}" Name="{AttributeName}"
Value="{AttributeValue}">
</Activity>

Some of these activities will have an attribute where Name = "Railcar
Number" (If there is any activities without a Railcar attribute, I will list
them on a separate page).  For these, each railcar must be on the same page
such as this:

Rail Car ABC12345
	Date	Tons	Amount
	4/1/03	25	1000
	4/12/03	75	3000
total:	100	4000
----PAGE BREAK----
Rail Car XYZ67890
	Date	Tons	Amount
	4/2/03	50	2000
	4/4/03	75	3000
	4/9/03	25	1000
total:	150	6000
----PAGE BREAK----
...

I have been able to get my data sorted in the xsl by Railcar then Date by
the time I get into the section <Activity>, yet I need to know when the rail
car changes so that I can put in the code for totals, page breaks, and the
header information.  I have figured out how to do everything else but this.

The following is one of the solutions that I thought might work (followed by
what I was thinking when I did this).

   <xsl:template match="Invoices/Invoice/Activity">
     <xsl:if test="position()!=1">
         <xsl:if test="Attribute[@Name='Railcar
Number']/Value=preceding-sibling::*[1]/Attribute[@Name='Railcar
Number']/Value">
           <fo:block font-size="10.0pt" font-family="serif"
text-align="start">
             page break
           </fo:block>
         </xsl:if>
       </fo:table-row>
     </xsl:if>
     <xsl:apply-templates select="Revenue"/>
   </xsl:template>

I first test the position() to be 1, since I do not need a page break on the
first page.

The next test, I attempt to look for the attribute with the name "Railcar
Number" (Attribute[@Name='Railcar Number']), then look at it's value (I have
tried examples such as /Value, @Value, and /@Value).

I will compare this to the preceding-sibling by
preceding-sibling::*[1]/Attribute[@Name='Railcar Number'], then I would
assume that what comes after this would be the same as followed the first
part of this test.



This does not seem to pass the parsing of the XSL.

If it helps, I am using xalan 2.2, xerces 1.4.4

Thanks,

David.

-----Original Message-----
From: bix xslt [mailto:bix_xslt@xxxxxxxxxxx] 
Sent: Thursday, April 10, 2003 5:02 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Grouping by an attribute of a child


>From: David Christiansen <DavidCh@xxxxxxxxxxxxxxxxxxx>
>I am trying to group records together so I can do subtotaling and page
>breaks.  I need to do this when the element "Attribute" with Attribute

David,

Would it be possible to restate your question?  I'm having trouble following

what the actual problem is.  Ie. What is your output with the xsl, and what 
do you want your output to be.

Thanks!
bix



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


Current Thread