This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Sorting Sibling Nodes !!!


Hi Ciaran,

> (NB - I need the output as <template></template> and not
> <template/>).

That's not something that you can control from within a stylesheet. If
you need that specific output structure, then you should probably
write a serialiser that you tack on to whatever processor you're using
to write out the tree in the way that you want it written out.
However, any XML application worth its salt will treat the two
versions in exactly the same way, so it's not clear why you care.

> I've tried this with the XSL below(Snippet!), However I'm getting
> duplicate outputs. Is this because the 'do' gets matched once as a
> sibling and a second time when I have <xsl:apply-templates
> select="following-sibling::do"/> ?.

Yes.  You can get around it by having the do-matching template in the
default mode do nothing:

<xsl:template match="do" />

And then apply templates from within the template-matching template in
'copy' mode:

<xsl:template match="template">
   <xsl:element name="{name()}">
      <xsl:apply-templates select="following-sibling::do"
                           mode="copy" />
   </xsl:element>
</xsl:template>

And add a mode to the do-matching template that you have currently:

<xsl:template match="do" mode="copy">
   <xsl:element name="{name()}">
      <xsl:apply-templates />
   </xsl:element>
</xsl:template>

(Is there any particular reason why you're using <xsl:element
name="{name()}" /> rather than <xsl:copy />?  They do do slightly
different things, so you could feasibly be doing it to get rid of
namespaces that you don't want, though in that case you should use
<xsl:element name="{local-name()}" /> instead.)

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]