[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Keeping comments with relevant node when shorting nodes

Subject: [xsl] Keeping comments with relevant node when shorting nodes
From: Mike Blake-Knox <mikebk824@xxxxxxxxx>
Date: Thu, 13 Jan 2005 17:31:59 -0500

I have several XML files like the following:

<!-- CNs-->
    <N name="N1">
            <M name="1N3"/>
            <M name="1N1"/>
            <M name="1N2"/>
     <N name="N2">
             <M name="2N2"/>
             <M name="2N3"/>
             <M name="2N1"/>

I'd like to sort them while keeping comments with the nodes they refer
to (e.g., keep <!--CN2--> with <M name="2N2"/>).

I've tried the following xslt:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="xml"/>

<xsl:template match="node() | @*">
    <xsl:apply-templates select="@* | node()"/>

<xsl:template match="Ns">
        <xsl:apply-templates select="comment()| N" >
          <xsl:sort select="@name"/>

It sorts fine but puts the comments  for all the N nodes together at
the top of the Ns element. I've played around with trying to group the
comments and N nodes using preceding-sibling but have not been

Any ideas?


Mike Blake-Knox

Current Thread