[xsl] Re: Template for node-set parents

Subject: [xsl] Re: Template for node-set parents
From: Darren Oh <darren@xxxxxxx>
Date: Mon, 5 Nov 2012 11:07:33 -0500
Thanks for all the suggestions. I succeeded by using an EXSL extension
function. I am writing code for PHP, so I have to use what PHP supports. Here
is my toy code:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:exsl="http://exslt.org/common"; extension-element-prefixes="exsl"
version="1.0">
 <xsl:output method="xml"/>
 <xsl:strip-space elements="*"/>
 <xsl:variable name="sorted">
   <xsl:for-each select="/response/data/result">
     <xsl:sort select="COMPANY_SORT" data-type="text" order="descending"/>
     <xsl:copy-of select="."/>
   </xsl:for-each>
 </xsl:variable>
 <xsl:template match="*">
   <xsl:copy>
     <xsl:apply-templates/>
   </xsl:copy>
 </xsl:template>
 <xsl:template match="/response/data/result">
   <xsl:variable name="position" select="position()"/>
   <xsl:copy-of select="exsl:node-set($sorted)/*[$position]"/>
 </xsl:template>
</xsl:stylesheet>

On Oct 19, 2012, at 1:03 PM, 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