[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: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Mon, 29 May 2006 14:33:59 +0530
last call template invoice
Hi Peter,
 Here is another solution using recursive named template

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="xml" indent="yes" />

<xsl:template match="/invoices">
 <invoices>
   <xsl:for-each select="invoiceHeader">
     <invoice>
       <xsl:copy-of select="." />
       <xsl:call-template name="outputinvoice">
         <xsl:with-param name="nodeset" select="following-sibling::*" />
       </xsl:call-template>
     </invoice>
   </xsl:for-each>
 </invoices>
</xsl:template>

<xsl:template name="outputinvoice">
 <xsl:param name="nodeset" />

 <xsl:if test="$nodeset[1]/self::invoiceLine">
   <xsl:copy-of select="$nodeset[1]" />
   <xsl:call-template name="outputinvoice">
     <xsl:with-param name="nodeset" select="$nodeset[position() &gt; 1]" />
   </xsl:call-template>
 </xsl:if>

</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

On 5/29/06, Munt,Peter (BOC eServices) <Peter.Munt@xxxxxxx> 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 - been at this for hours now... very bad I
know.


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).



<invoices>
 <invoiceHeader> ...</invoiceHeader>
 <invoiceLine>... </invoiceLine>
 <invoiceLine>... </invoiceLine>
 <invoiceLine>... </invoiceLine>
 <invoiceHeader>... </invoiceHeader>
 <invoiceLine>... </invoiceLine>
 <invoiceLine>... </invoiceLine>
</invoices>


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.

<invoices>
 <invoice>
  <invoiceHeader> ...</invoiceHeader>
  <invoiceLine>... </invoiceLine>
  <invoiceLine>... </invoiceLine>
  <invoiceLine>... </invoiceLine>
 </invoice>
 <invoice>
  <invoiceHeader>... </invoiceHeader>
  <invoiceLine>... </invoiceLine>
  <invoiceLine>... </invoiceLine>
 <invoice>
</invoices>


How can I do this ?


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.

<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" />
              </xsl:for-each>
           </invoiceLine>
        </invoice>

</xsl:for-each>



Thanks for any assistance

Peter

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.