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

RE: variable as select for template

Subject: RE: variable as select for template
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Wed, 19 Sep 2001 18:26:36 +0100
xsl select from template
> That was my try (it's a fragment):
>
> <xsl:variable name="parent_comp">  <!-- I wanted to get a node set in
> variable -->
>   <xsl:choose>
>    <xsl:when test="$comp_id=''">   <!-- the node set depends
> on a condition
> -->
>      <xsl:value-of select="component[@class=$comp_class and
> not(@id)]"/>
>    </xsl:when>
>    <xsl:otherwise>
>      <xsl:value-of select="component[@class=$comp_class and
> @id=$comp_id]"/>
>    </xsl:otherwise>
>   </xsl:choose>
> </xsl:variable>
>
> then i could use variable $parent_comp just as node set here
> and in other
> places in stylesheet:
> <xsl:apply-templates mode="extract_property" select="$parent_comp">
>
> If <xsl:value-of select"..."/> always get text() as result,
> are there any solutions???
>
Yes, there's a neat trick for this one:

<xsl:variable name="parent_comp"
  select="self::node()[$comp_id='']/
            component[@class=$comp_class and not(@id)] |
          self::node()[not($comp_id='')]/
            component[@class=$comp_class and @id=$comp_id]"/>

It's basically forming the union of two node-sets, one of which is always
empty.

The aboev is a general approach. Looking at the specific conditions used in
this case, there is actually a simpler solution. If $comp_id equals "", you
want the components with no @id attribute; otherwise you want those whose
@id attribute equals $comp_id. I'm assuming $comp_id is a string.

You can select these nodes as
select="component[@class=$comp_class and
        (($comp_id='' and not(@id)) or ($comp_id!='' and $comp_id=@id))]

Mike Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.