Node selection in XSLT

F

FaensenD

Can someone explain why of the following two alternative ways to select
as specific node the first one doesn't work while the second one does?

Variant I:

<recordToken>
<xsl:value-of select="/Root/Case[Id=./Id]/RecordToken" />
</recordToken>


Variant II:

<xsl:variable name="Id">
<xsl:value-of select="./Id" />
</xsl:variable>

<recordToken>
<xsl:value-of select="/Root/Case[Id=$Id]/RecordToken" />
</recordToken>

In Variant I we always get the value of RecordToken of the first Case
node in the XML document. In Variant II we get the RecordToken of the
Case that has the same Id as the current node.

Thank you

Daniel
 
J

Joris Gillis

Tempore 18:05:24 said:
Can someone explain why of the following two alternative ways to select
as specific node the first one doesn't work while the second one does?

Variant I:

<recordToken>
<xsl:value-of select="/Root/Case[Id=./Id]/RecordToken" />
</recordToken>

"./foo" is the same as "foo"

Your select is then basically: "/Root/Case[Id=Id]/RecordToken" Doesn't make much sense;-)

Inside a [predicate], the context node changes. But, lukily, you can recall the original context node via the XSLT function 'current()':

"/Root/Case[Id=current()/Id]/RecordToken"

In most situations, '.' and 'current()' are the same, but not inside a predicate.

regards,
 
M

Martin Honnen

Can someone explain why of the following two alternative ways to select
as specific node the first one doesn't work while the second one does?

Variant I:

<recordToken>
<xsl:value-of select="/Root/Case[Id=./Id]/RecordToken" />
</recordToken>

Well this works as defined but probably does not do what you want. I
guess you are looking for
<xsl:value-of select="/Root/Case[Id=current()/Id]/RecordToken" />

See <http://www.w3.org/TR/xslt#function-current>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,000
Messages
2,570,252
Members
46,848
Latest member
CristineKo

Latest Threads

Top