How to determine if param is defined in XSL

K

kforski

Hello

I wonder how can I find out if the param given to the xsl is defined
without error during compilation.

Actually I have such code (a part of it)

<xsl:if test="$showWarnings='true']">
<p><xsl:apply-templates select="$list" mode="errors"/></p>
</xsl:if>

But the $showWatnings can be undefined so I got error: "variable
"showWarnings" not defined". Some external (java) threads transform a
xml file with many data using the same xsl. Some of them define param
<xsl:param name="showWarnings">true</xsl:param> but others not and
those others shouldn't even know about such param.

Any idea?? Please?
 
J

Joe Kesselman

When you declare the parameter, set up a default value that you can
recognize as not having been passed in.
 
D

Dimitre Novatchev

Hello

I wonder how can I find out if the param given to the xsl is defined
without error during compilation.

Actually I have such code (a part of it)

<xsl:if test="$showWarnings='true']">
<p><xsl:apply-templates select="$list" mode="errors"/></p>
</xsl:if>

But the $showWatnings can be undefined so I got error: "variable
"showWarnings" not defined". Some external (java) threads transform a
xml file with many data using the same xsl. Some of them define param
<xsl:param name="showWarnings">true</xsl:param> but others not and
those others shouldn't even know about such param.

Any idea?? Please?

If the xsl:param is a global one, use this XPath expression to determine its
presence in the stylesheet:

document('')/*/xls:param[@name = 'showWarnings']

The above may not be usable if the stylesheet is dynamically generated (not
loaded from a file or URL).

Cheers,
Dimitre Novatchev
 
K

kforski

Could you please write a simple example how to use this expression in
such "if" clause?

Dimitre said:
Hello

I wonder how can I find out if the param given to the xsl is defined
without error during compilation.

Actually I have such code (a part of it)

<xsl:if test="$showWarnings='true']">
<p><xsl:apply-templates select="$list" mode="errors"/></p>
</xsl:if>

But the $showWatnings can be undefined so I got error: "variable
"showWarnings" not defined". Some external (java) threads transform a
xml file with many data using the same xsl. Some of them define param
<xsl:param name="showWarnings">true</xsl:param> but others not and
those others shouldn't even know about such param.

Any idea?? Please?

If the xsl:param is a global one, use this XPath expression to determine its
presence in the stylesheet:

document('')/*/xls:param[@name = 'showWarnings']

The above may not be usable if the stylesheet is dynamically generated (not
loaded from a file or URL).

Cheers,
Dimitre Novatchev
 
D

Dimitre Novatchev

Could you please write a simple example how to use this expression in
such "if" clause?

That's pretty basic XSLT:

<xsl:if test="document('')/*/xls:param[@name = 'showWarnings']">

<!-- The param is defined: Do whatever really needs to be done here -->

</xsl:if>


Dimitre said:
Hello

I wonder how can I find out if the param given to the xsl is defined
without error during compilation.

Actually I have such code (a part of it)

<xsl:if test="$showWarnings='true']">
<p><xsl:apply-templates select="$list" mode="errors"/></p>
</xsl:if>

But the $showWatnings can be undefined so I got error: "variable
"showWarnings" not defined". Some external (java) threads transform a
xml file with many data using the same xsl. Some of them define param
<xsl:param name="showWarnings">true</xsl:param> but others not and
those others shouldn't even know about such param.

Any idea?? Please?

If the xsl:param is a global one, use this XPath expression to determine
its
presence in the stylesheet:

document('')/*/xls:param[@name = 'showWarnings']

The above may not be usable if the stylesheet is dynamically generated
(not
loaded from a file or URL).

Cheers,
Dimitre Novatchev
 
J

Johannes Koch

Dimitre said:
<xsl:if test="document('')/*/xls:param[@name = 'showWarnings']">

Unless you map the prefix 'xls' to the XSLT namespace, you should write
'xsl:param'.
 
D

Dimitre Novatchev

Johannes Koch said:
Dimitre said:
<xsl:if test="document('')/*/xls:param[@name = 'showWarnings']">

Unless you map the prefix 'xls' to the XSLT namespace, you should write
'xsl:param'.


Oops... Thanks -- I only now see it's xls and not xsl

I think the OP made a typo, which I didn't notice. Of course, it must be:

<xsl:if test="document('')/*/xsl:param[@name = 'showWarnings']">


Also, the above implies that the "xsl" prefix is bound the usual way :eek:)

Cheers,
Dimitre Novatchev
 

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