I have to ask this question here...

Curtis
2005-02-24
2012-10-08
  • Curtis

    Curtis - 2005-02-24

    Dr. Kay, I know you want mulberry to handle XSLT questions, but I cannot get on the list because the US gov. has an entire server blocked that they use. This is a modern forum and the mulberry list is email, so it is not allowed. If there is another forum with a message board such as this then I will be glad to join it.

    Here is the latest post I tried to get through with:

    It is a continuation of the same problem I have been struggling with. Your explanation helped me to solve it.

    I have an element set in my XML document:
    <RPM>
    30.06
    40.05
    50.07
    60.07
    70.08
    80.12
    99.1
    100
    </RPM>
    I am attempting to find the largest number and as Dr. Kay pointed out on another
    forum, using...
    <xsl:variable name="rpm" select="max( for $i in tokenize($data/DataFile/RunData/RPM/text(),'\r?\n')
    return number($i) )"/>
    <xsl:value-of select="$rpm"/>
    will return the largest number. However I get NaN returned.

    It will work if the data is arranged as such:
    <RPM>30.06
    40.05
    50.07
    60.07
    70.08
    80.12
    99.1
    100</RPM>

    Thus, removing the line feeds and new lines at the top and bottom returns 100 instead
    of NaN (which is what I get because the tokenize creates 2 extra nodes at the top
    and bottom.

    My question is this: How can I create a node set from the above without tokenizing
    that is passed to the max() function (I think it needs the format max("1,2,3")) and
    will return what I need? Do I use the document function?

    There is another way to do this (as demonstrated in Sal Mangano's XSLT Cookbook)
    but I am trying to use 2.0 features.

    Thanks ahead of time.

    Curtis Fisher

     
    • Michael Kay

      Michael Kay - 2005-02-24

      I guess this isn't the worst restriction of personal liberty that the US government has imposed in the name of security, so I sympathise with your problems.

      Your simplest solution is to apply normalize-space() to the list before you tokenize it. This will get rid of the leading and trailing separators, it also means you can use the simpler regular expression "\s".

      An even better solution would be to use schema-aware stylesheet processing. If your source document were validated against a schema that described the content of RPM as a list-of-xs:decimal values, then you could simply write max($data/DataFile/RunData/RPM) and the system would already know what data type and tokenization rules to use.

      Michael Kay

       
    • Curtis

      Curtis - 2005-02-25

      Thank you for your help, a very simple solution and proof that I was getting so wrapped up in the trees, I forgot to look around the forest!

      Sincerely,

      Curtis Fisher

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks