[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 511
  • Last Modified:

xslt, xpath filtering

Hi,

I have the attached xml and I am using Altova stylevision to transorm the xml in html. This tool uses xslt and xpath.

What I cannot figure out how to do is obtain the name attribute of weekday but only for the occurrence with the maximum Revenue.

Your expert advice is most welcome.

Thanks in advance.
myxml.xml
0
robespierre_2010
Asked:
robespierre_2010
  • 4
  • 2
2 Solutions
 
Geert BormansInformation ArchitectCommented:
you can get there by sorting the nodes and pick the first one
    <xsl:template match="DailyData">
        <xsl:for-each select="WeekDay">
            <xsl:sort select="Revenue" data-type="number" order="descending"/>
            <xsl:if test="position() = 1">
                <xsl:copy-of select="."/>
            </xsl:if>
        </xsl:for-each>

Open in new window

0
 
robespierre_2010Author Commented:
Hi,
Thanks for your help.

I am using sort and then position()=1, as you suggested.

However, the field for which I am sorting is giving me sompe the following problem:

The values the field takes are 40.55; 38.23; 78.94; ...; 100

 position()=1 is not retrieving the occurrence with value 100 but the highest occurrence where the value is of type xx.yy which in this case would be 78.94

Is this a problem related to the schema definition? Do you know how to make sure that the evaluation of position()=1 takes into consideration the value of 100?

Regards.
0
 
Geert BormansInformation ArchitectCommented:
well there are a lot of flaws in the XSLT engines of Altova (they simply suck in my opinion :-)
erroneous sorting is one of the flaws.
If this is XSLT2 there also might be the issue of not implicitely casting to number
so maybe it is a good idea to change the sort like this
            <xsl:sort select="number(Revenue)" data-type="number" order="descending"/>
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
robespierre_2010Author Commented:
this last issue was solved by changing the data type from text to nnumeric in the sort dialog in Altova stylevision.
0
 
robespierre_2010Author Commented:
thanks a lot
0
 
robespierre_2010Author Commented:
by the way, what would be your tool of choice if not altova?
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now