xsl-list
[Top] [All Lists]

Re: [xsl] Template for node-set parents

2012-11-01 16:29:53
My solution assumed XSLT 2.0. I think that these days, if you want to use XSLT 1.0, you should say so - it's been superseded for nearly 6 years now.

I'm afraid I don't do 1.0 solutions for people - my memories of how to get round its restrictions are fading rapidly. But there are probably other people on the list who can help.

Michael Kay
Saxonica

On 01/11/2012 21:14, Darren Oh wrote:
Thanks for the suggestion. I got stuck when trying to produce a sorted 
node-set. Instead of a node-set, I got a result tree fragment, for which no 
node-set operations are possible. Here is a simplified example to illustrate 
the problem. Whereas it is possible to select a node from $result, it is not 
possible to select a node from $sorted. Any ideas?

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
   <xsl:output method="xml"/>
   <xsl:template match="*">
     <xsl:copy>
       <xsl:apply-templates/>
     </xsl:copy>
   </xsl:template>
   <xsl:variable name="result" select="/response/data/result"/>
   <xsl:variable name="sorted">
     <xsl:apply-templates select="/response/data/result">
       <xsl:sort select="COMPANY_SORT" data-type="text" order="descending"/>
     </xsl:apply-templates>
   </xsl:variable>
   <xsl:template match="/">
     <xsl:copy-of select="$result[1]"/>
     <xsl:copy-of select="$sorted[1]"/>
   </xsl:template>
</xsl:stylesheet>

On Oct 19, 2012, at 1:27 PM, Michael Kay wrote:

Try:

1. define a global variable $v1 that selects the result of the path expression 
in document order.

2. define another global variable $v2 that selects the sorted result of the 
path expression

3. Use a base template rule that's the identity copy

4. Add a template rule that matches nodes in $v1 (match="node()[. intersect $v1]). In this 
rule, determine the index position of this node in $v1 (count ($v1[. << $this]) + 1), and 
output the corresponding node from $v2 (copy-of select="$v2[$n]").

Michael Kay
Saxonica


On 19/10/2012 18:03, Darren Oh wrote:
I am trying to generate a stylesheet that copies an XML source document. The 
only change should be that nodes selected by an XPath expression are sorted. I 
want this to work for any XML source document. The only information available 
to generate the stylesheet is the XPath expression and the sort criteria. I 
think this requires creating a template for the parents of the nodes selected 
by the XPath expression. How can I do this?
--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>