Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: problem with dynamic sort and quotes in parameter value

From: "Chris Barber" <chris@----------.--.--.------>
To: 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 &quot; and &apos; 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




transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent