RE: [xsl] Question about variable assignment based on run-time value

Subject: RE: [xsl] Question about variable assignment based on run-time value
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 2 Nov 2009 20:29:40 -0000
> I'm trying to capture a sequence of nodes in a variable. The 
> catch is that the nodes I capture can vary based on the 
> local-name() of the element matched by the template.
> 
> I've got:
> 
> <xsl:variable name="label-nodes">
>      <xsl:choose>
>          <xsl:when test="local-name() = 'shared'">
>              <xsl:value-of select="rm:label[$page-type = 
> tokenize(@pages, '\s*,\s*')]"/>
>          </xsl:when>
>          <xsl:otherwise>
>              <xsl:value-of select="rm:label"/>
>          </xsl:otherwise>
>      </xsl:choose>
> </xsl:variable>
> 
> Instead, I want the sequence of rm:label elements selected by 
> the XPath expression in the xsl:value-of instruction's select 
> attribute. But how do I select a sequence?

Well, the minimum change is:

> <xsl:variable name="label-nodes">
>      <xsl:choose>
>          <xsl:when test="local-name() = 'shared'">
>              <xsl:sequence select="rm:label[$page-type = tokenize(@pages,
'\s*,\s*')]"/>
>          </xsl:when>
>          <xsl:otherwise>
>              <xsl:sequence select="rm:label"/>
>          </xsl:otherwise>
>      </xsl:choose>
> </xsl:variable>

But I think I would write

<xsl:variable name="label-nodes"
  select="rm:label[local-name(current()) ne 'shared' or $page-type =
tokenize(@pages, '\s*,\s*')]"/>

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

Current Thread