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

sorting before transforming

Subject: sorting before transforming
From: Dan Miner <dminer@xxxxxxxxxxxxxxxx>
Date: Fri, 20 Jul 2001 13:32:00 -0600 (MDT)
dan miner
I'm new to XSLT and I've been having pretty good results; however, I've
hit a spot where input sorting is required.

I have an element called <text> which I will display in an HTML file.
However, I have a number of special spots in this text which I
want to highlight in some way.  This can be reasonably done by
having the start positions within the text to be sorted.  But
this isn't the case in the source XML. 

What I'd like to do is sort a list of nodes and then transform
this sorted node list.  <xsl:sort> appears to only work on the
resulting output and can not be applied to the input document.

Is it possible to sort nodes in the input?  If not, is there a way
to "chain" stylesheets?  [ XML1 -> XSL1 -> XML2 -> XSL2 -> XML3, etc]

Samples: (using Xalan-Java 2 on Linux)

<list>
<text>This is a test string.</text>
<prop1>
<startpos>0</startpos>
<length>1</length>
</prop1>
<prop1>
<startpos>6</startpos>
<length>1</length>
</prop1>
<prop2>
<startpos>3</startpos>
<length>1</length>
</prop2>
</list>

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
  <xsl:output method="html"/>
 
  <xsl:template match="/">
    <xsl:apply-templates select="//list"/>
  </xsl:template>
 
  <xsl:template match="list">
    <xsl:for-each select="*[startpos]">
      <xsl:value-of select="startpos"/>, <xsl:value-of select="length"/>, <xsl:value-of select="following-sibling::*/startpos - startpos"/>
      ---
    </xsl:for-each>
  </xsl:template>
 
</xsl:stylesheet>


It outputs:
0, 1, 6
      ---
    6, 1, -3
      ---
    3, 1, NaN
      ---



	Regards,
		Dan

-- 
 Dan Miner     dan@xxxxxxxxx |   "That vulnerability is completely    | Doing
        Linux & UNIX         |      theoretical." -- Microsoft        | Linux
    Programmer/Consultant    | "What yonder light Windows 95 breaks?" | since
                             |    "Free software: The New Frontier"   | v0.12
------------------------------------------------------------------------------
       By filing this bug report, you have challenged the honor of my
       family.  PREPARE TO DIE!

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


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.