XSLT nightmare

G

gwoodhouse

Hello, hopefully someone can help with this - i must be missing some
knowledge on XSLT variables because to my mind this should work:

What im trying to do is check if variable1 has variable2 contained
within it. To do that i wrote this code:

<xsl:when test="fn:contains($selectedNode, @name)">

This doesnt work getting a null pointer error for @name. So i wrote
this bit of debug:

1 <xsl:value-of select="fn:length($selectedNode)"/>
2 <xsl:value-of select="@name"/>
3 <xsl:variable name="jim"><xsl:value-of select="@name"/></
xsl:variable>
4 <xsl:value-of select="$jim"/>
5 <xsl:value-of select="fn:length($jim)"/>

This also falls over on instruction 5 giving this output:

1 48
2 bob
3
4 bob
5

As you can see it just doesnt seem to like using the variable in any
functions - but as you can also see it uses a global xsl:param
variable correctly and gives the right length.

What is it that im missing?

Thanks

Graeme
 
M

Martin Honnen

Hello, hopefully someone can help with this - i must be missing some
knowledge on XSLT variables because to my mind this should work:

What im trying to do is check if variable1 has variable2 contained
within it. To do that i wrote this code:

<xsl:when test="fn:contains($selectedNode, @name)">

This doesnt work getting a null pointer error for @name. So i wrote
this bit of debug:

1 <xsl:value-of select="fn:length($selectedNode)"/>
2 <xsl:value-of select="@name"/>
3 <xsl:variable name="jim"><xsl:value-of select="@name"/></
xsl:variable>
4 <xsl:value-of select="$jim"/>
5 <xsl:value-of select="fn:length($jim)"/>

I don't see any function named 'length' defined in
http://www.w3.org/TR/xpath-functions/#quickref-alpha so I have no clue
what you want to achieve.

What do you want to achieve? Which version of XSLT do you use? Which
XSLT processor do you use?
 
P

Peter Flynn

Hello, hopefully someone can help with this - i must be missing some
knowledge on XSLT variables because to my mind this should work:

What im trying to do is check if variable1 has variable2 contained
within it. To do that i wrote this code:

<xsl:when test="fn:contains($selectedNode, @name)">

The contains() function is a string function, so the above will scan the
string representation of $selectedNode's content for occurrences of the
value of @name.

I don't see anything called variable1 or variable2 there.
This doesnt work getting a null pointer error for @name.

That sounds as if your expression is not in the context node that you
think it is.

So i wrote
this bit of debug:

1 <xsl:value-of select="fn:length($selectedNode)"/>
2 <xsl:value-of select="@name"/>
3 <xsl:variable name="jim"><xsl:value-of select="@name"/></
xsl:variable>
4 <xsl:value-of select="$jim"/>
5 <xsl:value-of select="fn:length($jim)"/>

This also falls over on instruction 5 giving this output:

1 48
2 bob
3
4 bob
5

If I understand this right, the length of the string value of
$selectedNode is 48 characters, and the value of @name is "bob". So $jim
now contains the string "bob" and you won't get anything from [5]
because there is no such function as length() and I'm surprised you got
anything from the first call in [1]. Did you mean string-length()? Why
has your processor not issued an error message about length()?

I don't see anything here about the contains() function. Are we still
talking about the same problem?
As you can see it just doesnt seem to like using the variable in any
functions - but as you can also see it uses a global xsl:param
variable correctly and gives the right length.

You had better provide us with a complete [non-]working minimal example
that we can execute to watch it fail. Trying to do this stuff without
the actual instances is not very useful. And often the exercise of
constructing a minimal example reveals the problem while you do it.

///Peter
 

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,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top