[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: Florent Georges <darkman_spam@xxxxxxxx>
Date: Wed, 27 Jun 2007 19:27:47 +0200 (CEST)
Re:  Variable in XPath
Garvin Riensche wrote:

  Hi

> <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?

  I think that if you can use XSLT 2.0, the more straight
forward would be to defined your predicates as functions:

    <xsl:function name="my:equals" as="xs:boolean">
      <xsl:param name="lhs" as="attribute()"/>
      <xsl:param name="rhs" as="item()?"/>
      <xsl:sequence select="
          if ( empty($rhs) ) then
            true()
          else
            $lhs eq $rhs"/>
    </xsl:function>

    <xsl:function name="my:matches" as="xs:boolean">
      <xsl:param name="elem"  as="element()"/>
      <xsl:param name="id"    as="item()?"/>
      <xsl:param name="owner" as="item()?"/>
      <xsl:param name="name"  as="item()?"/>
      <xsl:sequence select="
          my:equals($elem/@id, $id)
            and my:equals($elem/@owner, $owner)
            and my:equals($elem/@name, $name)"/>
    </xsl:function>

and then in your code:

    <xsl:if test="my:matches(the-elem, 'id', 'owner', 'name')">

  If the values to test against are global parameters, just
use:

    <xsl:function name="my:matches" as="xs:boolean">
      <xsl:param name="elem" as="element()"/>
      <xsl:sequence select="
          my:equals($elem/@id, $id)
            and my:equals($elem/@owner, $owner)
            and my:equals($elem/@name, $name)"/>
    </xsl:function>

and:

    <xsl:if test="my:matches(the-elem)">

  Regards,

--drkm





















	

	
		
___________________________________________________________________________ 
Dicouvrez une nouvelle fagon d'obtenir des riponses ` toutes vos questions ! 
Profitez des connaissances, des opinions et des expiriences des internautes sur Yahoo! Questions/Riponses 
http://fr.answers.yahoo.com

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.