B
Brandolon Hill
Hi,
Is there a way to check and see if a parameter is defined in XSLT?
I have many stylesheets that all have an <xsl:include> of the same
stylesheet, "foo.xsl".
Foo relies on several parameters that all contain the names of various
XML tags. Foo.xsl then performs a standard action (outputting the
information in HTML) on the tag given by the parameter.
I'm doing this in the context of a content management system. Each
content item has it's own XML structure, so I might have
person.xsl:
car.xsl:
<car>
<model>Gremlin</model>
</car>
<person>
<name>Bob</name>
</person>
Each content type (car, person) has its own XSL, but foo.xsl performs
tasks that need to be done for every content type (generally determining
what locale to display in).
So car.xsl has <xslaram name="printMeNode" select="string('model')"/>
and person.xsl has <xslaram name="printMeNode"
select="string('name')"/>. Both car.xsl and person.xsl then do an
xsl:include of foo.xsl.
Then foo.xsl has
xmlns:dynamic="http://exslt.org/dynamic"
....
<xsl:for-each select="dynamic:evaluate($printMeNode)">
<xsl:value-of select="."/>
</xsl:for-each>
(Evaluate is a function that turns a string into a node-set.)
But I'm not the only person who is going to be writing the content type
XSLs, and while I've put dire warnings everywhere I could, I still want
to be able to print an output message if the printMeNode parameter isn't
found so the other developer will know what the heck is going on.
Right now, if printMeNode isn't there, the error message is a cryptic
"Could not find variable with the name of printMeNode". I'm using
Xalan, by the way.
So is there any way to check and ensure that a parameter/variable is
defined? Maybe I'm going about this in the wrong way entirely?
*Any* suggestions, comments will be greatly appreciated.
Is there a way to check and see if a parameter is defined in XSLT?
I have many stylesheets that all have an <xsl:include> of the same
stylesheet, "foo.xsl".
Foo relies on several parameters that all contain the names of various
XML tags. Foo.xsl then performs a standard action (outputting the
information in HTML) on the tag given by the parameter.
I'm doing this in the context of a content management system. Each
content item has it's own XML structure, so I might have
person.xsl:
car.xsl:
<car>
<model>Gremlin</model>
</car>
<person>
<name>Bob</name>
</person>
Each content type (car, person) has its own XSL, but foo.xsl performs
tasks that need to be done for every content type (generally determining
what locale to display in).
So car.xsl has <xslaram name="printMeNode" select="string('model')"/>
and person.xsl has <xslaram name="printMeNode"
select="string('name')"/>. Both car.xsl and person.xsl then do an
xsl:include of foo.xsl.
Then foo.xsl has
xmlns:dynamic="http://exslt.org/dynamic"
....
<xsl:for-each select="dynamic:evaluate($printMeNode)">
<xsl:value-of select="."/>
</xsl:for-each>
(Evaluate is a function that turns a string into a node-set.)
But I'm not the only person who is going to be writing the content type
XSLs, and while I've put dire warnings everywhere I could, I still want
to be able to print an output message if the printMeNode parameter isn't
found so the other developer will know what the heck is going on.
Right now, if printMeNode isn't there, the error message is a cryptic
"Could not find variable with the name of printMeNode". I'm using
Xalan, by the way.
So is there any way to check and ensure that a parameter/variable is
defined? Maybe I'm going about this in the wrong way entirely?
*Any* suggestions, comments will be greatly appreciated.