[Home] [By Thread] [By Date] [Recent Entries]
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 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):
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>
|

Cart



