|
Subject: RE: [xsl] variable as select for template From: "Michael Kay" <mhkay@xxxxxxxxxxxx> Date: Wed, 19 Sep 2001 18:26:36 +0100 |
> 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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] variable as select for te, Jörg Heinicke | Thread | RE: [xsl] variable as select for te, Dmitri Ilyin |
| RE: [xsl] How do you get the non-tr, Wendell Piez | Date | [xsl] Absolute paths in document() , Adam Van Den Hoven |
| Month |