|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: variable as select for template
> -----Original Message----- > From: Michael Kay [mailto:mhkay@xxxxxxxxxxxx] > Sent: Wednesday, September 19, 2001 7:27 PM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: variable as select for 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 > Whau.... It's so simple. It seems i have to learn yet a little ;) Thanks Mike Dmitri XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






