RE: [xsl] Error when params are in Xpath expression

Subject: RE: [xsl] Error when params are in Xpath expression
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 12 May 2009 20:00:53 +0100
> Actually, I think now you have
> document('')/*/trans:tr/tr_string[@str=$str]/*[name()=$toLang]"
> Note the slight alteration in the predicate in the last step.
> >Then there is a question of which format would be faster for 
> Xpath to 
> >test to see if string exists in a desired language?
> Beats me. I think examining the @lang attribute might be a 
> tiny bit faster than using the name() function. I doubt the 
> difference would be noticeable unless documents got very large.

Assuming you have 5000 strings in 5 languages, the cost of finding the right
language is going to be negligible compared with finding the right string.
But it might well be worth keying the strings on the combination of the two:

<xsl:key name="k"  match="tr_string/*" use="concat(../@str, '#', @lang)"/>

and then replace the above path with:

key('k', concat($str, '#', $toLang))


Michael Kay 

Current Thread