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

Re: flattening and re-ordering nested notes

Subject: Re: flattening and re-ordering nested notes
From: Walter Lee Davis <waltd@xxxxxxxxxxxx>
Date: Mon, 18 Aug 2008 13:37:35 -0400
Re:  flattening and re-ordering nested notes
On Aug 18, 2008, at 12:06 PM, Andrew Welch wrote:

Put in the effort to create an example input and required output and
someone might post the code to turn that input into that output...


Thanks in advance if you can help:

http://pastie.org/254986


So the sample input is:

[snip]
Better than nothing, but both can be shortened down to:

Input:

<publication>
  <document>
    <div>
      <note id="note1">
        <note id="note2"/>
       </note>
    </div>
  </document>
</publication>

Output:

<publication>
  <document>
    <div/>
    <note id="note1"/>
    <note id="note2"/>
  </document>
</publication>

...which demonstrates the same problem, but with all unrelated
information removed.  This sort of small, complete example is what you
should be aiming for when posting a question to a mailing list.

Thanks for the example, I'll try to remember that in the future. I was hoping to spare the bulk of the list having to slog through the whole thing, hence the use of pastie. I did initially post something this brief, but was asked for more detail, hence the additional content (really quite a lot shortened from the original 340K document).



Here's a transform that should do what you need:


<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs">

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

<xsl:template match="note"/>

<xsl:template match="document">
	<xsl:copy>
		<xsl:apply-templates select="@*|node()"/>
	</xsl:copy>
	<xsl:apply-templates select="//note" mode="notes"/>
</xsl:template>

</xsl:stylesheet>

If you are stuck with 1.0 it will take a bit more effort because it
doesn't have mode="#all" (you just have to copy the identity template
and put it in the mode="notes")

I am indeed stuck in 1.0, so just to clarify, do you mean that I need to create a new template, mode="notes" and put it at the same level as the identity template, and then remove the mode="#all" bit from the identity template?




-- Andrew Welch


Thanks very much for your help, this looks extremely promising.

Walter

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.