[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] problem with handling conditional for loops


Subject: Re: [xsl] problem with handling conditional for loops
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Wed, 27 Apr 2005 10:00:56 -0500

 ----------------------
> <xsl:for-each select="document(First.xml)/SubConcepts/SubConcept">
>         <xsl:variable name="clsName" select="@name"/>
>         <xsl:for-each
> select="document(Second.xml)/SubConcepts/SubConcept[1]/Value">
>             ..........
>             <xsl:choose>
>                 <xsl:when
>
test="contains(normalize-space(lower-case($ontSecondVal)),normalize-space(low
er-case($clsName)))">
>                     <xsl:call-template name="firstLevel">
>                         ..........
>                     </xsl:call-template>
>                 </xsl:when>
>                 <xsl:otherwise>
>                     ...............
>                 </xsl:otherwise>
>             </xsl:choose>
>         </xsl:for-each>
>   </xsl:for-each>
> ---------------------
>
> IN CASE I dont find $clsName in any of the Value/text() of
> SubConcept[1], I'd like to loop though the remaining SubConcept nodes to
> check whether $clsName exists in its @name.
>
> I hope this is slightly clearer. Else please let me know.

Yes, it seems much clearer to me.  I'll try to give you a quick
response, but I don't have time at the moment to actually verify it.

I have a feeling a refinement of your xpath is all that is needed but
for some reason it's not coming today.  I'm sure the others on the
list can come up with one though if it exists.

If what you're really looking for is the first Value element that has
a valid $clsName (not sure what meets this criteria) you can get the
group of all that meet the criteria and return the first of that set.

<xsl:variable name="Values"
select="document(Second.xml)/SubConcepts/SubConcept/Value/@name[some
test to determine if clsName]"/>
<xsl:variable name="clsName" select="$Values[1]">

This of course hasn't been tested, but might be what you are looking
for.  It really has little to do with the parent loop.

Jon Gorman


Current Thread
Keywords