OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: Inquiry: Reordering XML elements through XSL

[ Lists Home | Date Index | Thread Index ]
  • From: "G. Ken Holman" <gkholman@CraneSoftwrights.com>
  • To: XML-Dev Mailing list <xml-dev@ic.ac.uk>
  • Date: Fri, 18 Jun 1999 21:06:31 -0700

At 99/06/19 10:12 +0700, James Clark wrote:
>> At 99/06/18 18:34 -0700, Aaron Fischer wrote:
>> >However, this still leaves the reverse problem of translating from a tag
>> >order of AAABBB to ABABAB.
>A simpler approach is:
>perform the following on the document element "test"
>  for each a element
>    copy the element
>    let n be the position of this a element (ie this element is the n-th
>a element)
>    copy the n-th of the following b siblings

When I read this I thought this would only work when the number of <a>
elements is not less than the number of <b> elements, so I tried an example
below to confirm that.

Although Aaron's example has an equal number of elements, I tried to be
more general by handling an arbitrary number of either element (though I
don't know if this is his need or not).  The approach I took is based on a
numerical index rather than relying on the existence of either element.

Certainly if we stick to his original example, your code works, so I was
just playing outside the sandbox.

........... Ken

T:\fischer>type test3.xml
<a name="kathryn"/>
<a name="kaitlyn"/>
<b name="ken"/>
<b name="alex"/>
<b name="ted"/>
<b name="john"/>

T:\fischer>type jclark3.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
<xsl:template match="test">
   <xsl:for-each select="a">
     <xsl:copy-of select="."/>
     <xsl:variable name="n" expr="position()"/>
     <xsl:copy-of select="from-following-siblings(b[$n])"/>

T:\fischer>call xsl test3.xml jclark3.xsl test4.xml
T:\fischer>type test4.xml
<a name="kathryn"/>
<b name="ken"/>
<a name="kaitlyn"/>
<b name="alex"/>


G. Ken Holman                    mailto:gkholman@CraneSoftwrights.com
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Publications:   Introduction to XSLT (3rd Edition) ISBN 1-894049-00-4

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo@ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@ic.ac.uk)


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS