This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How best to use recursion/call-templates?


You can use the key() function to output a <span> for each unique account 
number, and also to select all the other accounts with that same number:

<xsl:key name="row" match="row" use="account"/>
<xsl:template match="row">
  <xsl:if test="count(key('row', account)[1] | .) = 1">
    <span>
      <xsl:value-of select="account"/>
      <xsl:for-each select="key('row', account)">
        <a><xsl:value-of select="name"/></a>
      </xsl:for-each>
    </span>
  </xsl:if>
</xsl:template>

There shouldn't be any need for a recursive template (or even a named 
template).

On Wednesday 27 February 2002 14:37, David T. wrote:
> If I have this XML fragment:
>
> <xml>
>  <row>
>     <account>32</account>
>     <name>Smith</name>
>  </row>
>  <row>
>     <account>32</account>
>     <name>Jones</name>
>  </row>
>  <row>
>      <account> 35</account>
>      <name>White</name>
>  </row>
> </xml>
>
> ....then I'd like this output
>
> <span> 32
>    <a>smith</a>
>    <a>Jones</a>
> </span>
>  <span>  35
>     <a> White </a>
>  </span>
>
> In other words:  each account number is in its own <span> tag, and each
> name that has that account # is a link (<a>) inside that span tag.  Since
> Jones and Smith both have the same account #, they are inside the same
> span tags.  Since White has a different account number, there is a
> separate <span> tag.
>
> 1.  How can I achieve this output?
> 2.  Should I use recursion to achieve this?
> 3.  Is this a procedural problem and should I rethink my approach?
>
> What I have tried:  I have tried a number of call-template functions but I
> never seem to get the right result, primarily because I never quite nail
> down the right params to send. I've also tried using preceding-sibling to
> work through this, but I got deeper into trouble.  I'd post my XSL but
> it's terribly convoluted now.   I am admittedly lost. Any suggestions?
>
> David.
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

-- 
Peter Davis
"We'll look into it":
	By the time the wheels make a full turn, we
	assume you will have forgotten about it, too.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]