Because you asked for them in your output. That is to say, your sample output
showed them as being passed through to the output unchanged.
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email
-----Original Message-----
From: António Mota <amsmota(_at_)gmail(_dot_)com>
Sent: Thu, 6 Jan 2005 19:39:25 +0000
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Group various elements with empty tags (flat XML structure
to hierarcial XML)
Why do you need
<xsl:template match="id|type|count|language">
<xsl:copy-of select="." />
</xsl:template>
??
On Thu, 06 Jan 2005 14:29:15 -0500, cknell(_at_)onebox(_dot_)com
<cknell(_at_)onebox(_dot_)com> wrote:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Record">
<Record>
<xsl:apply-templates />
</Record>
</xsl:template>
<xsl:template match="id|type|count|language">
<xsl:copy-of select="." />
</xsl:template>
<xsl:template match="firstname">
<NAME>
<xsl:copy-of select="." />
<xsl:copy-of select="following-sibling::lastname[1]" />
</NAME>
</xsl:template>
<xsl:template match="street">
<ADDRESS>
<xsl:copy-of select="." />
<xsl:copy-of select="following-sibling::city[1]" />
<xsl:copy-of select="following-sibling::country[1]" />
<xsl:copy-of select="following-sibling::postal_code[1]" />
</ADDRESS>
</xsl:template>
<xsl:template
match="initial|lastname|city|country|postal_code|amount1|amount2|amount3" />
</xsl:stylesheet>
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email
-----Original Message-----
From: M Glenties <mglenties(_at_)hotmail(_dot_)com>
Sent: Thu, 06 Jan 2005 13:55:59 -0500
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Group various elements with empty tags (flat XML structure to
hierarcial XML)
I need to convert a flat xml document to something more hierarcial by
surrounding some elements with other empty elements.
Original XML:
------------
<Record>
<id>102</id>
<type>O</Type>
<count>37</count>
<firstname>Joe</firstname>
<lastname>Smith</lastname>
<initial>A</initial>
<street>35 Main Street</street>
<city>Moosejaw</city>
<country>Sasaktchewan</country>
<postal_code>TOEOPO</postal_code>
<amount1>1.23</amount1>
<amount2>4.56</amount2>
<amount3>7.89</amount3>
<language>E</language>
</Record>
Desired Output:
--------------
<Record>
<id>102</id>
<type>O</Type>
<count>37</count>
<NAME>
<firstname>Joe</firstname>
<lastname>Smith</lastname>
</NAME>
<ADDRESS>
<street>35 Main Street</street>
<city>Moosejaw</city>
<country>Saskatchewan</country>
<postal_code>TOEOPO</postal_code>
</ADDRESS>
<language>E</language>
</Record>
My stylesheet:
-------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Record">
<Record>
<xsl:apply-templates select="lastname" mode="Name"/>
<xsl:apply-templates select="postal_code" mode="PC"/>
</Record>
</xsl:template>
<xsl:template match="lastname" mode="Name">
<NAME>
<xsl:apply-templates
select="preceding::firstname[generate-id(following::lastname[1]) >
generate-id(current())]"/>
<xsl:apply-templates select="."/>
</NAME>
</xsl:template>
<xsl:template match="postal_code" mode="PC">
<ADDRESS>
<xsl:apply-templates
select="preceding::street[generate-id(following::postal_code[1]) >
generate-id(current())]"/>
<xsl:apply-templates select="."/>
</ADDRESS>
</xsl:template>
<xsl:template match="Record/*">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
My output:
--------------
<NAME>
<firstname>Joe</firstname>
<lastname>Smith</lastname>
</NAME>
<ADDRESS>
<street>35 Main Street</street>
<postal_code>TOEOPO</postal_code>
</ADDRESS>
Can anyone tell me where I have gone wrong? I'm missing <id>, <type> etc,
and my xsl returns only 2 elements when more are sometimes required.
Thanks for your time,
M Glenties
_________________________________________________________________
MSN® Calendar keeps you organized and takes the effort out of scheduling
get-togethers.
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
Start enjoying all the benefits of MSN® Premium right now and get the
first two months FREE*.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--