[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Keeping comments with relevant node when shorting

Subject: RE: Keeping comments with relevant node when shorting nodes
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 14 Jan 2005 23:56:30 -0000
shorting in xsl
Sounds like it might be a good idea to do an initial pass that wraps the N
element and its preceding comments in a wrapper element. That's a positional
grouping problem:

<xsl:for-each-group select="child::node()" group-ending-with="N">
  <wrapper>
    <xsl:copy-of select="current-group()"/>
  </wrapper>
</xsl:for-each-group>

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Mike Blake-Knox [mailto:mikebk824@xxxxxxxxx] 
> Sent: 14 January 2005 20:33
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re:  Keeping comments with relevant node when 
> shorting nodes
> 
> That sorts nicely but unfortunately, we have several comments in front
> of some node.
> 
> I haven't been able to come up with a method of grouping the comments
> with their associated nodes. Would you have any suggestions?
> 
> The current xsl is:
> 
> <?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:copy>
> <xsl:apply-templates select="@* | node()"/>
> </xsl:copy>
>    </xsl:template>
> 
>  <xsl:template match="Ns">
>      <xsl:copy>
>          <xsl:apply-templates select="N">
>             <xsl:sort select="@name"/>
>        </xsl:apply-templates>
>      </xsl:copy>
> </xsl:template>
> 
> <xsl:template match="N">
> <xsl:copy-of 
> select="preceding-sibling::node()[normalize-space()][1][self::
> comment()]
> "/>
> <xsl:copy-of select="."/>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> 
> 
> On Thu, 13 Jan 2005 23:21:51 -0000, Michael Kay 
> <mike@xxxxxxxxxxxx> wrote:
> > Try:
> > 
> > <xsl:apply-templates select="N">
> >  <xsl:sort select="@name"/>
> > </xsl:apply-templates>
> > 
> > <xsl:template match="N">
> >  <xsl:copy-of select="preceding-sibling::comment()[1]
> >  <xsl:copy-of select="."/>
> > </xsl:template>
> > 
> > This assumes that every N element has an associated comment.
> > 
> > Michael Kay
> > http://www.saxonica.com/
> > 
> > > -----Original Message-----
> > > From: Mike Blake-Knox [mailto:mikebk824@xxxxxxxxx]
> > > Sent: 13 January 2005 22:32
> > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > Subject:  Keeping comments with relevant node when 
> shorting nodes
> > >
> > > I have several XML files like the following:
> > >
> > > <!-- CNs-->
> > > <Ns>
> > >     <!--CN1-->
> > >     <N name="N1">
> > >         <Ms>
> > >             <!--C1N3-->
> > >             <M name="1N3"/>
> > >             <!--C1N1-->
> > >             <M name="1N1"/>
> > >             <!--C1N2-->
> > >             <M name="1N2"/>
> > >         </Ms>
> > >     </N>
> > >     <!--CN2-->
> > >      <N name="N2">
> > >          <Ms>
> > >              <!--C2N2-->
> > >              <M name="2N2"/>
> > >              <!--C2N3-->
> > >              <M name="2N3"/>
> > >              <!--C2N1-->
> > >              <M name="2N1"/>
> > >          </Ms>
> > >      </N>
> > > </Ns>
> > >
> > >
> > > 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:copy>
> > >     <xsl:apply-templates select="@* | node()"/>
> > >   </xsl:copy>
> > > </xsl:template>
> > >
> > > <xsl:template match="Ns">
> > >     <xsl:copy>
> > >         <xsl:apply-templates select="comment()| N" >
> > >           <xsl:sort select="@name"/>
> > >         </xsl:apply-templates>
> > >     </xsl:copy>
> > > </xsl:template>
> > > </xsl:stylesheet>
> > >
> > > 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
> > > succesful.
> > >
> > > Any ideas?
> > >
> > > Thanks
> > >
> > > --
> > > Mike Blake-Knox
> > 
> > 
> 
> 
> -- 
> Mike Blake-Knox

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.