[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: Florent Georges <darkman_spam@xxxxxxxx>
Date: Mon, 29 May 2006 11:05:18 +0200 (CEST)
xsltproc for each group
"Munt,Peter (BOC eServices)" wrote:

> What I need is a <invoice> tag that surrounds the Header
> and Lines.

  If you use XSLT 2.0, you can use xsl:for-each-group:

    ~> cat drafts/grouping-2.xsl
    <xsl:transform
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="2.0">

      <xsl:output indent="yes"/>

      <xsl:template match="invoices">
        <xsl:copy>
          <xsl:for-each-group
              select="*"
              group-starting-with="invoiceHeader">
            <invoice>
              <xsl:copy-of select="current-group()"/>
            </invoice>
          </xsl:for-each-group>
        </xsl:copy>
      </xsl:template>

    </xsl:transform>

    ~> cat drafts/grouping-2.xml
    <invoices>
      <invoiceHeader>A</invoiceHeader>
      <invoiceLine>A 1</invoiceLine>
      <invoiceLine>A 2</invoiceLine>
      <invoiceLine>A 3</invoiceLine>
      <invoiceHeader>B</invoiceHeader>
      <invoiceLine>B 1</invoiceLine>
      <invoiceLine>B 2</invoiceLine> 
    </invoices>

    ~> saxon drafts/grouping-2.xml drafts/grouping-2.xsl
    <?xml version="1.0" encoding="UTF-8"?>
    <invoices>
       <invoice>
          <invoiceHeader>A</invoiceHeader>
          <invoiceLine>A 1</invoiceLine>
          <invoiceLine>A 2</invoiceLine>
          <invoiceLine>A 3</invoiceLine>
       </invoice>
       <invoice>
          <invoiceHeader>B</invoiceHeader>
          <invoiceLine>B 1</invoiceLine>
          <invoiceLine>B 2</invoiceLine>
       </invoice>
    </invoices>

  If you are restricted to XSLT 1.0, you can recurse on
adjacent lines:

    ~> cat drafts/grouping-1.xsl
    <xsl:transform
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">

      <xsl:output indent="yes"/>

      <xsl:template match="invoices">
        <xsl:copy>
          <xsl:apply-templates select="invoiceHeader"/>
        </xsl:copy>
      </xsl:template>

      <xsl:template match="invoiceHeader">
        <invoice>
          <xsl:copy-of select="."/>
          <xsl:apply-templates select="
              following-sibling::*[1][self::invoiceLine]"/>
        </invoice>
      </xsl:template>

      <xsl:template match="invoiceLine">
        <xsl:copy-of select="."/>
        <xsl:apply-templates select="
            following-sibling::*[1][self::invoiceLine]"/>
      </xsl:template>

    </xsl:transform>

    ~> xsltproc drafts/grouping-1.xsl drafts/grouping-2.xml
    <?xml version="1.0"?>
    <invoices>
      <invoice>
        <invoiceHeader>A</invoiceHeader>
        <invoiceLine>A 1</invoiceLine>
        <invoiceLine>A 2</invoiceLine>
        <invoiceLine>A 3</invoiceLine>
      </invoice>
      <invoice>
        <invoiceHeader>B</invoiceHeader>
        <invoiceLine>B 1</invoiceLine>
        <invoiceLine>B 2</invoiceLine>
      </invoice>
    </invoices>

  Regards,

--drkm





























	

	
		
___________________________________________________________________________ 
Faites de Yahoo! votre page d'accueil sur le web pour retrouver directement vos services prifiris : virifiez vos nouveaux mails, lancez vos recherches et suivez l'actualiti en temps riel. 
Rendez-vous sur http://fr.yahoo.com/set

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.