Hi Andrew,
Thanks for your answer but it's not exactly that what I was looking for.
Maybe I have to explain my problem a bit more. Consider again the
following XML:
<facts>
<class id="2" owner="1" name="A"/>
<class id="3" owner="1" name="B"/>
<facts>
This is a simple example, there might be input with nodes containing
more attributes.
For each attribute there has to be a variable, $id, $owner and $name in
this case, which is set from commandline. When writing the stylesheet I
dont't know which classes are goint to be selected. This could be all
classes, classes selected by id, classes selected by id and name, ect.
So there are lots of possibilities - and even more if there are more
attributes. The stylesheet would be very large if I would use a
<xsl:when> for every possible combination. So my idea was to use a
default value for each variable, so that all (class) nodes are selected
if the variable is not set.
For example:
I call saxon with $owner="1" $name="A" then $id is empty and I want the
following test to return true:
<xsl:when test="doc('factbase.xml')/facts/class[(_at_)id eq $id and @owner eq
$owner and @name eq $name]">
This will return false because $id is empty. My quesion is, is there a
default value that I can put in the select of <xsl:variable name="id"
select"?????"/> so that the test above will return true?
It would be great if that would work somehow because with lots of
<xsl:when>s I think it would be much more complicated (considering more
attributes).
regards,
Garvin
On 6/27/07, Andrew Welch <andrew(_dot_)j(_dot_)welch(_at_)gmail(_dot_)com>
wrote:
Seems like a long-winded way of just saying you want to check if
<class> exists:
<xsl:when test="doc('factbase.xml')/facts/class">
If you then want to do something specific if the @id eq $id then add a
condition inside the xsl:when.
Or its probably cleaner to just add another when:
<xsl:when test="doc('factbase.xml')/facts/class[(_at_)id eq $id]">
there is a class with a matching @id
</xsl:when>
<xsl:when test="doc('factbase.xml')/facts/class">
there are one or more class elements, but none of them a matching @id
</xsl:when>
<xsl:otherwise>
this aren't any class elements...
</xsl:otherwise>
You'd want to refactor the call to doc() into a variable too.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--