xsl-list
[Top] [All Lists]

Re: problem with handling conditional for loops

2005-04-27 08:35:47
Theres only one problem though in this solution. For instance the
$clsName returns values 'Hello', 'How', 'Are', 'You' each time the
for-loop executes, extracting a node value from First.xml one at a time.
My XPaths differ in how I look for the existence of 'Hello' etc. in
SubConcept[1] and the rest of the SubConcept's.

(1) First I use the XPath -
document(Second.xml)/SubConcepts/SubConcept[1]/Value and match if text()
= $clsName

(2) If 'Hello' etc. isnt available in (1) then I look for it using the
XPath -  document(Second.xml)/SubConcepts/SubConcept/@name and match if
@name=$clsName

Ah, typing too quickly and I missed that we were using clsName for
comparison, not as a target variable to fill.  I don't have much time,
so I"ll only give it one more shot before concluding that I'll have to
wait till I have time to look at it closer.

Like I said, the outer parent loop seems to be a red herring.  It has
little to do with the problem at hand.  Might be misreading the
matter.

But since you need to apply different xpaths we can do something
similar...might be some scoping problems here (might have to move it
so the <xsl:variable wraps around) but something like this should work
 (although I'm suspicious of the text(), it would seem to me you need
. or something similar).

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

<xsl:otherwise>
<xsl:variable name="Values"
select="document(Second.xml)/SubConcepts/SubConcept/Value/@name[.=$clsName]"/>
<xsl:variable name="nodeToProcess" select="$Values[1]">
</xsl:otherwise>
</xsl:when>

I wouldn't be surprised if there are some gotchas in this.  But it
should be a direction to look at.

Moreover Second.xml is a
very large file and I would prefer to save execution time by avoiding
duplicate match finds. 

Sorry, not sure how you could save your time here.  It would depend
heavily on the parser/processor.  Flipping through each node in a
for-each loop might even take more time than selecting them as a
group.  There are others that might be able to respond.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--