[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Variable in XPath

Subject: Re: Variable in XPath
From: Garvin Riensche <g.riensche@xxxxxxx>
Date: Wed, 27 Jun 2007 18:02:52 +0200
Re:  Variable in XPath
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[@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.j.welch@xxxxxxxxx> 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[@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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.