Sunday, June 28, 2009

small xpath problem

I was met with a small problem with xpath. While learning it seemed simple. Using it in xslt, and especially with namespace makes it very complicated. I still have problem with xpath axes. I need to access the attribute value of the parent node, which is also the root node. I wrote the xpath as:
xsl:value-of select="/x:index/@userid"
However, the root node is not always same, so the absolute path doesn't work. I tried the xpath axes; however, I'm always getting syntax error, for example:
xsl:value-of select="parent::attribute::@userid"
It seems the xslt doesn't like it with I use axis more than once. I suppose perhaps I should use a node right after parent:: ? But I need to access the parent's attribute, there's no node below for me to use. What to do? I still don't know how to use the xpath axes. I'm using a lazy method for now, but it might become problematic:
xsl:value-of select="/x:*/@userid"


Update:
Oh! It's stupid!! After all the bloody searches and trials i gone through, the solution is stupidly simple. -_-# The xPath also works, in case, like dos, like normal directory - all I needed was two dots and a slash to tell it to search one level up, so:
xsl:value-of select="../@userid"
... ... ...

No comments:

Powered By Blogger