Re: [xsl] Identifying unique attribute values in nested sibling elements

Subject: Re: [xsl] Identifying unique attribute values in nested sibling elements
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 04 Oct 2011 20:50:08 -0400
At 2011-10-04 07:23 -0700, Mark wrote:
Despite my confused presentation of the problem
last week, you supplied me with two functions
that obtain the unique attributes from  <Value>
element within a set of <Stamp> elements. Works
beautifully, but I did make some modifications
to the second function. Please let me know if my
modifications are consistent with the idiom you
have been talking about or if I have slipped back into C++.

You have made one slip to note.


       <!-- kc-value + h-value -->
       <xsl:when test="Value/@h-value">
         <xsl:variable name="h">
           <xsl:for-each select="Value/@h-value">
             <xsl:value-of select="."/>
           </xsl:for-each>
         </xsl:variable>

The waste is that you are creating a two-node variable consisting of a document node and a text node, then later only getting the variable's text value.

The above could simply be: <xsl:variable name="h" select="Value/@h-value"/>

Then you are simply pointing to the existing node
in the tree and getting that node's value at each
reference.  And since the node is an attribute
node, the node's value is self-contained and no
calculations or tree traversals are needed (as is
true for obtaining an element's value or a
document node's value which was true for your attempt).

         <xsl:for-each select="Value/@kc-value">
           <xsl:choose>
             <xsl:when test="not(. eq '0')">
               <a class="button" href="../aval/{concat(., '-', $h)}.htm">
                 <xsl:value-of select="concat(., '.', $h)"/>
                 <xsl:text>KD
</xsl:text>
               </a>
             </xsl:when>
             <xsl:otherwise>
               <a class="button" href="../aval/{concat(., '-', $h)}.htm">
                 <xsl:value-of select="$h"/>
                 <xsl:text>h</xsl:text>
               </a>
             </xsl:otherwise>
           </xsl:choose>
         </xsl:for-each>

Oh, I know earlier you indicated your preference for being more explicit about what is going on with concatenation, but I would make another change:

</xsl:when>

       <xsl:otherwise>
         <!-- Only when there is no h-value  -->
         <xsl:for-each select="Value/@kc-value">
           <a class="button" href="../aval/{concat(., '-0')}.htm">

I would have used: href="../aval/{.}-0.htm"


I hope this helps.

. . . . . . . . . . . Ken

--
Contact us for world-wide XML consulting and instructor-led training
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

Current Thread