xsl-list
[Top] [All Lists]

Re: [xsl] Positional Grouping problem

2006-05-29 01:50:46
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(_at_)CraneSoftwrights(_dot_)com
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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