![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - problem with dynamic sort and quotes in parameter value [Thread Next] Re: problem with dynamic sort and quotes in parameter valueTo: NULL Date: 5/7/2004 3:19:00 AM The filter expression has to be on the select for the xsl:for-each or else there would be fewer sort
values than actual items.
This XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">
<xsl:output indent="yes" method="xml" omit-xml-declaration="no"/>
<!-- Sorted nodelist -->
<xsl:variable name="rtf-sorted-nodeset">
<xsl:for-each select="/Objects/SingleObject[@DisplayName='Description']">
<xsl:sort select="DisplayValue"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<!-- convert RTF to node-set -->
<xsl:variable name="sorted-nodeset" select="msxsl:node-set($rtf-sorted-nodeset)/*"/>
<xsl:template match="/">
<items>
<xsl:for-each select="$sorted-nodeset">
<xsl:copy-of select="."/>
</xsl:for-each>
</items>
</xsl:template>
</xsl:stylesheet>
On this XML:
<Objects>
<SingleObject id="1" DisplayName="Description">
<DisplayValue>Item1</DisplayValue>
</SingleObject>
<SingleObject id="1a" DisplayName="NotADescription">
<DisplayValue>Item1a</DisplayValue>
</SingleObject>
<SingleObject id="3" DisplayName="Description">
<DisplayValue>Item3</DisplayValue>
</SingleObject>
<SingleObject id="2" DisplayName="Description">
<DisplayValue>Item2</DisplayValue>
</SingleObject>
<SingleObject id="4" DisplayName="NotADescription">
<DisplayValue>Item4</DisplayValue>
</SingleObject>
</Objects>
Produces:
<?xml version="1.0" encoding="UTF-16"?>
<items>
<SingleObject id="1" DisplayName="Description">
<DisplayValue>Item1</DisplayValue>
</SingleObject>
<SingleObject id="2" DisplayName="Description">
<DisplayValue>Item2</DisplayValue>
</SingleObject>
<SingleObject id="3" DisplayName="Description">
<DisplayValue>Item3</DisplayValue>
</SingleObject>
</items>
Which I believe achieves what you wanted?
Chris.
"Kai Cohrt" <kuewchen@g...> wrote in message
news:59e96733.0405061552.454a3421@p......
Hi there,
I tried to find a solution on the newsgroup but even though lots of
threads look at similar problems I could not find a solution.
I have a xsl sheet that works fine this way:
...
<xsl:variable name="rtf-sorted-nodeset">
<xsl:for-each select="/Objects/SingleObject">
<xsl:sort select="Attributes/Attr[DisplayName='Description']/DisplayValue"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<!-- convert RTF to node-set -->
<xsl:variable name="sorted-nodeset"
select="msxsl:node-set($rtf-sorted-nodeset)/*"/>
<xsl:template match="/">
...
But if I want to pass in that sort value as parameter value I get into
trouble with the 'Description' part of the XPath expression. I tried:
<xsl:param name="paramSortAttr1"
select='"Attributes/Attr[DisplayName='Description']/DisplayValue"'>
and
<xsl:param name="paramSortAttr1"
select="'Attributes/Attr[DisplayName='Description']/DisplayValue'">
and all kind of " and ' combination.
In the sort section I try to get the param value with
<xsl:sort select="*[name() = $paramSortAttr1]"/>
But like I said, the second approach does not work.
Can anybody give me an idea what is wrong?
Thank you very much,
Kai
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
