Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XPath with variables

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
I have a XML file that looks like this:


I have a stylesheet, that looks like that:


I would like to change the XPath Expression to point the language that is in curLanguage. I tried
select="priority-key[level=$curPrio]/$curLanguage"
select="priority-key[level=$curPrio]/{$curLanguage}"
select="priority-key[level=$curPrio]/'{$curLanguage}'"

but without success. How does the correct XPath look like?
;-) stw


ps:
Disabled smiles.
- m
[ June 29, 2004: Message edited by: Madhav Lakkapragada ]
 
Nimchi Yung
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<xsl:template match="priorities"><xsl aram name="curLanguage"/><xsl aram name="curPrio"/><xsl:value-ofselect="priority-key[level=$curPrio]/English"/></xsl:template>


I think your XPath expr should be like this:




--Nimchi
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nimchi,
thx for taking the time to reply. From your reply I see, that I didn't phrase my question clearly. The xpath
actually does work well. What I want to achieve is to replace English by the content that is in $curLanguage.
This is a very fundamental problem for me: how to construct an xPath expression where the name of a node is a variable. I tried to poke around with the name() function but no luck. The w3school tutorials didn't answer this question too (or I missed it).
;-) stw
 
Porky Liu
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
maybe you can get all the element under priority-key, and then get the correct element with xsl:if test current() = $whatever, just like this

It's not easy, but I do think it can work
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Porky Liu,

thx for your reply. I did a little reevaluating of XLST concepts. You actually can't compare a node to a string. So the solution is to look for something that is a string inside the node. The riddle is solved when you use the name() function. to the answer is:

;-) stw
[ July 07, 2004: Message edited by: Stephan H. Wissel ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic