This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
sorting before transforming
- To: XSL-LIST at lists dot mulberrytech dot com
- Subject: [xsl] sorting before transforming
- From: Dan Miner <dminer at edison dot chisp dot net>
- Date: Fri, 20 Jul 2001 13:32:00 -0600 (MDT)
- Reply-To: xsl-list at lists dot mulberrytech dot com
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@miner.org | "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