Subject: Re: [xsl] Positional Grouping problem From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 29 May 2006 17:49:02 +0900 |
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
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 ?
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" />
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: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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Positional Grouping problem, Munt,Peter \(BOC eSe | Thread | Re: [xsl] Positional Grouping probl, Mukul Gandhi |
[xsl] Positional Grouping problem, Munt,Peter \(BOC eSe | Date | Re: [xsl] Positional Grouping probl, Mukul Gandhi |
Month |