xslt: multiple node match for one template: how?

T

Tjerk Wolterink

I've made the following template:

<xsl:template match="form:string or form:e-mail or form:url or form:password">
[cut]
</xsl:template>

But the match attribute has an invalid xpath pattern, so i tried this:

<xsl:template match=".[node()=form:string or node()=form:e-mail or node()=form:url or node()=form:password]">
[cut]
</xsl:template>

But that too is not valid!

How should i solve this?
 
J

Joris Gillis

I've made the following template:
<xsl:template match="form:string or form:e-mail or form:url or form:password">
[cut]
</xsl:template>

Hi,

I think that should be:

<xsl:template match="form:string | form:e-mail | form:url | form:password">
[cut]
</xsl:template>


regards,
 
M

Martin Honnen

Tjerk said:
I've made the following template:

<xsl:template match="form:string or form:e-mail or form:url or
form:password">
[cut]
</xsl:template>

But the match attribute has an invalid xpath pattern, so i tried this:

<xsl:template match=".[node()=form:string or node()=form:e-mail or
node()=form:url or node()=form:password]">
[cut]
</xsl:template>

But that too is not valid!

How should i solve this?

Are you looking for
<xsl:template match="form:string | form:e-mail | form:url |
form:password">
maybe?
 
T

Tjerk Wolterink

Martin said:
Tjerk said:
I've made the following template:

<xsl:template match="form:string or form:e-mail or form:url or
form:password">
[cut]
</xsl:template>

But the match attribute has an invalid xpath pattern, so i tried this:

<xsl:template match=".[node()=form:string or node()=form:e-mail or
node()=form:url or node()=form:password]">
[cut]
</xsl:template>

But that too is not valid!

How should i solve this?


Are you looking for
<xsl:template match="form:string | form:e-mail | form:url |
form:password">
maybe?

Ok that solved my problem,

but it raises a new question:

In xpath or is the or operator, why use | in xslt??

I think it has something todo with that you do not want a boolean return value from the expression in the match,
you want a node to be returned, am i right?
 
T

Tjerk Wolterink

Ok now i have the following problem:

i've:

<xsl:template match="form:string | form:e-mail | form:url | form:password">
<xsl:if test="current()=form:password">
[cut]
</xsl:if>
</xsl:template>

But the test in the if tag does not work, how should i check wether the current() is a form:password??

name(.)='password' does not help
current()=form:password does not help

please help
 
J

Joris Gillis

In xpath or is the or operator, why use | in xslt??
I think it has something todo with that you do not want a boolean return value from the expression in the match,
you want a node to be returned, am i right?
you're right

the '|' is the union operator for node-sets, while 'or' and 'and' does boolean logic (they return not node-set but a boolean value)
 
J

Joris Gillis

<xsl:if test="current()=form:password">
[cut]
</xsl:if>
</xsl:template>

But the test in the if tag does not work, how should i check wether the current() is a form:password??

Normally, you test something like that with 'self::node'.
But I'm not sure how to handle the namespace. one guess: 'self::form:password'
 
D

David Carlisle

use | not or
or is an Xpath boolean operator an XSLT patterns have to match nodes not
boolean values.

David
 

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

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top