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 12:48:45 -0500
Hi Rahil,


> Sorry trouble already. $nodeToProcess now correctly contains values
> found in either the <xsl:when> or <xsl:otherwise> statement.
>
> However how can I also add the value of the 'id' attribute to
> $nodeToProcess so that I can look for references to the result based on
> its id at a later stage ?
>
> E.g. <Value id="1234">Hello</Value>

I have a feeling you are having some problems with the difference
between selecting node-sets and result tree fragments...see
http://www.dpawson.co.uk/xsl/sect2/nodeset.html for more on that.

But a better answer is I think you might be better served by templates
in here.  Since I'm not sure of the complete structure of your code
I'll have to guess a little bit.

But we use the structure like we had before but instead of assigning a
variable for later processing we will pass it to a template that will
generate the appropriate result:

<xsl:choose>
<xsl:when
test="document(Second.xml)/SubConcepts/SubConcept[1]/Value[$clsName=text()]">

<xsl:call-template name="processNode">
<xsl:with-param name="nodeToProcess"
select="document(Second.xml)/SubConcepts/SubConcept[1]/Value[$clsName=text()]
"/>
<xsl:with-param name="$ontSecondVal" select="$ontSecondVal" />
<!-- and whatever other parameters you need to produce the appropriate
output -->
</xsl:when>
<xsl:otherwise>
<xsl:variable name="Values"
select="document(Second.xml)/SubConcepts/SubConcept/Value/@name[.=$clsName]"/
>
<xsl:call-template name="processNode">
<xsl:with-param name="nodeToProcess" select="$Values[1]">
</xsl:otherwise>
</xsl:when>

...
<xsl:template name="processNode">
<xsl:param name="processNode" />
...
</xsl:template>

This might be difficult, but it seems to be the best way to preserve
the nodeset.  But I'm pretty sure there is a better way to do
it.....can't think of it now.


Jon Gorman

Current Thread