View Single Post
  #5 (permalink)  
Old July 9th, 2007, 05:50 PM
tall rog tall rog is offline
Registered User
 
Join Date: Jul 2007
Location: Wroclaw, , Poland.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tall rog
Default

Mike,

  thanks a lot... I got it working by using...
      <xsl:variable name="sorted-CMPs" as="attribute()*">
  otherwise I got a type error..

  The fact that if you use a path then it always accesses the nodes in document order is rather nasty. Dare I say... not logical. If I create an variable with ordered elements then I expect them to be ordered no matter how I access the nodes.

So if I use the following test input XML...

<TEST>
    <FLD1 attr1='attr11' attr2='attr12' attr3='attr13'>
        <CMP num='11'>11</CMP>
        <CMP num='13'>13</CMP>
        <CMP num='12'>12</CMP>
        <CMP num='14'>14</CMP>
    </FLD1>

    <FLD1 attr1='attr24' attr2='attr25' attr3='attr26'>
        <CMP num='21'>21</CMP>
        <CMP num='23'>23</CMP>
        <CMP num='22'>22</CMP>
    </FLD1>

    <FLD1 attr1='attr04' attr2='attr05' attr3='attr06'>
        <OTH num='OTH'/>
        <CMP num='02'>02</CMP>
        <CMP num='01'>01</CMP>
    </FLD1>
</TEST>


THIS DOES NOT WORK..
Because I am selecting an an attribute of the elements contain in the variable using a path.
      <xsl:variable name="sorted-CMPs" as="element()*">
         <xsl:perform-sort select="CMP">
            <xsl:sort select="./@num"/>
         </xsl:perform-sort>
      </xsl:variable>

      <xsl:value-of select="($sorted-CMPs/@num,
          'NA', 'NA', 'NA', 'NA', 'NA')[position()=1 to 5]"
        separator="|"/>
      <xsl:text>|</xsl:text>


THIS DOES WORK (assuming I wanted to order the value of the CMP elements and not on the num attribute of the CMP element)
It works because I am not accessing the value of the elements contain in the variable using a path.
      <xsl:variable name="sorted-CMPs" as="element()*">
         <xsl:perform-sort select="CMP">
            <xsl:sort select="."/>
         </xsl:perform-sort>
      </xsl:variable>

      <xsl:value-of select="($sorted-CMPs,
          'NA', 'NA', 'NA', 'NA', 'NA')[position()=1 to 5]"
        separator="|"/>
      <xsl:text>|</xsl:text>


AND THIS WORKS AS WELL
Because in the same manner, I am selecting the content of the variable without using a path.
      <xsl:variable name="sorted-CMPs" as="attribute()*">
         <xsl:perform-sort select="CMP/@num">
            <xsl:sort select="."/>
         </xsl:perform-sort>
      </xsl:variable>

      <xsl:value-of select="($sorted-CMPs,
          'NA', 'NA', 'NA', 'NA', 'NA')[position()=1 to 5]"
        separator="|"/>
      <xsl:text>|</xsl:text>


  It just seem wrong. To the point that I would be reporting this as a bug in Saxon if I had come across this by myself. I am sure there is or at least was a good reason for it. But I sure as hell can not see what it is.

Roger




---------------------------------------------------------
Insert witty interesting comment here...
Reply With Quote