[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Positional Grouping problem

Subject: Re: Positional Grouping problem
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 29 May 2006 17:49:02 +0900
xslt positional grouping
At 2006-05-29 17:30 +1000, Munt,Peter \(BOC eServices\) wrote:
I have read the FAQ and think I have found a partial answer to my
problem.  Seems to be Positional Grouping solution (10)
http://www.dpawson.co.uk/xsl/sect2/N4486.html

but my xslt skills are too weak to understand the solution!.  I can't
even get the solution to work

You were close.


I have the following XML  - a Batch of Invoices  a 3 line Invoice and a
2 line Invoice (there are a bunch of other tags and data inside these
but for simplicity I've left then out in this example).
...
What I need is a <invoice> tag that surrounds the Header and Lines.
There is nothing that relates a Header to a Line apart from its position
i.e the header will be followed by its lines.
...
How can I do this ?

A solution is below.


Something like the partial example snippet given in the FAQ above would
give the following - but can somebody fill in the blanks  - I am missing
the start template statements etc - but I do not know what they are
meant to be.

It is difficult to guess what you need, but there is a fault in your snippet (ignoring all the "==" faults):


   <xsl:for-each select=="invoiceHeader">
         <invoice>
            <invoiceHeader><xsl:value-of select="." />
            </invoiceHeader>

            <invoiceLine>
               <xsl:for-each select=="following-sibling::invoiceLine[
count(preceding-sibling::invoiceHeader[1] | current()) == 1]">
               <xsl:value-of select=="invoiceLine" />

The above creates a single invoice line, not one per each following sibling.


For help on "the start template statements etc." most XSLT books discuss the top-level requirements for stylesheets. There is a free download on our web site of the first two chapters and all other chapter introductions of the XSLT book we sell from our web site ... you can see working examples there. Check the links at the right side of our home page linked blow. There are also many web sites with introductory information on XSLT.

For the wrapping bit, I hope the code below helps.

. . . . . . . . . . Ken

T:\ftemp>type peter.xml
<invoices>
 <invoiceHeader> ...</invoiceHeader>
 <invoiceLine>... </invoiceLine>
 <invoiceLine>... </invoiceLine>
 <invoiceLine>... </invoiceLine>
 <invoiceHeader>... </invoiceHeader>
 <invoiceLine>... </invoiceLine>
 <invoiceLine>... </invoiceLine>
</invoices>

T:\ftemp>type peter.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output indent="yes"/>

<xsl:template match="invoices">
  <invoices>
    <xsl:for-each select="invoiceHeader">
      <invoice>
        <invoiceHeader><xsl:value-of select="."/></invoiceHeader>
        <xsl:for-each select="following-sibling::invoiceLine[
            count(preceding-sibling::invoiceHeader[1] | current()) = 1]">
          <xsl:copy-of select="."/>
        </xsl:for-each>
      </invoice>
    </xsl:for-each>
  </invoices>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>xslt peter.xml peter.xsl con
<?xml version="1.0" encoding="utf-8"?>
<invoices>
   <invoice>
      <invoiceHeader> ...</invoiceHeader>
      <invoiceLine>... </invoiceLine>
      <invoiceLine>... </invoiceLine>
      <invoiceLine>... </invoiceLine>
   </invoice>
   <invoice>
      <invoiceHeader>... </invoiceHeader>
      <invoiceLine>... </invoiceLine>
      <invoiceLine>... </invoiceLine>
   </invoice>
</invoices>
T:\ftemp>


-- Registration open for XSLT/XSL-FO training: Wash.,DC 2006-06-12/16 Also for XSL-FO/XSLT training: Minneapolis, MN 2006-07-31/08-04 Also for XML/XSLT/XSL-FO/UBL training: Varo,Denmark 06-09-25/10-06 World-wide corporate, govt. & user group UBL, XSL, & XML training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.