[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Recently submitted a post requesting help with sorting. my situation is still the same. i am merging many documents. i get the sort to work but not correctly. it appears to be looking at only the first node of each file and sorting the files according to the first node. i need to sort each individual file first. then merge the sort of all file, or sort each file then merge all.
mastermerge.xsl
=====================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:preserve-space elements="text"/>
<xsl:template match="masterfile">
<merged>
<table style="border:1px solid #000000;border-collapse:collapse">
<xsl:apply-templates select="document(doc/@filename)/client">
<!-- <xsl:sort select="name"/> -->
<xsl:sort select="subclient/name/lname" />
</xsl:apply-templates>
</table>
</merged>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="translate(., '

', ' ')"/>
</xsl:template>
<xsl:template match="client/subclient">
<xsl:copy>
<!-- <tr>
<th>
<xsl:apply-templates select="title"/>
</th>
</tr> -->
<tr>
<td style="border:1px solid #000000">
<!-- <xsl:apply-templates select="@*|node()"/> -->
<!-- <xsl:apply-templates select="name"/> -->
<xsl:for-each select="name">
<xsl:sort select="lname" order="ascending"/>
<xsl:value-of select="fname"/>
<xsl:text> </xsl:text>
<xsl:value-of select="lname"/>
</xsl:for-each>
<!--
<xsl:apply-templates select="lname"/> -->
</td>
<td style="border:1px solid #000000">
<xsl:apply-templates select="phones"/>
</td>
<td style="border:1px solid #000000">
<xsl:apply-templates select="address"/>
</td>
</tr>
</xsl:copy>
</xsl:template>
<!-- <xsl:for-each select="name">
<xsl:sort select="lname"/>
<xsl:value-of select="fname"/>
</xsl:for-each> -->
<xsl:template match="address">
<xsl:for-each select="line">
<xsl:apply-templates/>
<br/>
</xsl:for-each>
<xsl:value-of select="url"/>
<br/>
<xsl:value-of select="email"/>
<br/>
</xsl:template>
<xsl:template match="name">
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
====================================
file1.xml
====================================
[xsl] sorting issue
Subject: [xsl] sorting issue From: cookie king <cookieking@xxxxxxxxxxx> Date: Wed, 29 Jun 2005 20:57:04 -0400 |
Recently submitted a post requesting help with sorting. my situation is still the same. i am merging many documents. i get the sort to work but not correctly. it appears to be looking at only the first node of each file and sorting the files according to the first node. i need to sort each individual file first. then merge the sort of all file, or sort each file then merge all.
mastermerge.xsl
=====================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:preserve-space elements="text"/>
<xsl:template match="masterfile">
<merged>
<table style="border:1px solid #000000;border-collapse:collapse">
<xsl:apply-templates select="document(doc/@filename)/client">
<!-- <xsl:sort select="name"/> -->
<xsl:sort select="subclient/name/lname" />
</xsl:apply-templates>
</table>
</merged>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="translate(., '

', ' ')"/>
</xsl:template>
<xsl:template match="client/subclient">
<xsl:copy>
<!-- <tr>
<th>
<xsl:apply-templates select="title"/>
</th>
</tr> -->
<tr>
<td style="border:1px solid #000000">
<!-- <xsl:apply-templates select="@*|node()"/> -->
<!-- <xsl:apply-templates select="name"/> -->
<xsl:for-each select="name">
<xsl:sort select="lname" order="ascending"/>
<xsl:value-of select="fname"/>
<xsl:text> </xsl:text>
<xsl:value-of select="lname"/>
</xsl:for-each>
<!--
<xsl:apply-templates select="lname"/> -->
</td>
<td style="border:1px solid #000000">
<xsl:apply-templates select="phones"/>
</td>
<td style="border:1px solid #000000">
<xsl:apply-templates select="address"/>
</td>
</tr>
</xsl:copy>
</xsl:template>
<!-- <xsl:for-each select="name">
<xsl:sort select="lname"/>
<xsl:value-of select="fname"/>
</xsl:for-each> -->
<xsl:template match="address">
<xsl:for-each select="line">
<xsl:apply-templates/>
<br/>
</xsl:for-each>
<xsl:value-of select="url"/>
<br/>
<xsl:value-of select="email"/>
<br/>
</xsl:template>
<xsl:template match="name">
<xsl:apply-templates/>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
====================================
file1.xml
====================================
<client> <subclient> <title>A</title> </subclient> <subclient> <name> <fname>Jack</fname> <lname>John</lname> </name> <phones> <phone/> <ext/> <fax/> </phones> <address> <line>address 1</line> <line>address 2</line> <url>www.what.com</url> <email/></address> </subclient> </client> =================================== masterfile.xml =================================== <masterfile> <doc filename="file1.xml"/> <doc filename="file2.xml"/> </masterfile>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] adding escaping slashes, Joe Stump | Thread | Re: [xsl] sorting issue, David Carlisle |
RE: [xsl] Traversing nodes and stor, Aron Bock | Date | [xsl] Re: [exslt] Re: [xsl] Importi, Colin Paul Adams |
Month |
Keywords