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

Re: Template for node-set parents

Subject: Re: Template for node-set parents
From: Darren Oh <darren@xxxxxxx>
Date: Thu, 1 Nov 2012 17:14:51 -0400
Re:  Template for node-set parents
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?

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.