[xsl] Re: xsl-list Digest 30 May 2006 05:10:00 -0000 Issue 791

Subject: [xsl] Re: xsl-list Digest 30 May 2006 05:10:00 -0000 Issue 791
From: Chad Chelius <cchelius@xxxxxxxxxxxxxxx>
Date: Wed, 31 May 2006 13:58:58 -0400
I am trying to do something very similar to this as well. In my situation, I have the following XML file:

<document>
	<title>
	<subtitle>

There are many more elements with the <document> element but I'm focused one the ones listed above right now. I need to create an element called <group> that is a parent to the <title> and <subtitle> elements so that my resulting file looks like this:

<document>
	<group>
		<titile>
		<subtitle>

I think my question correlates to this post, but I can't figure out how to incorporate it into my situation. I am certainly an XSLT newbie so I apologize if I'm off track here.


On May 30, 2006, at 1:10 AM, xsl-list-digest- help@xxxxxxxxxxxxxxxxxxxxxx wrote:


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>

Current Thread