Re: [xsl] Nestled <xsl:choose>

Subject: Re: [xsl] Nestled <xsl:choose>
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sat, 14 Jul 2001 09:15:22 +0100
Hi Oliver,

> I'm trying to create a testing structure to assign a different
> template depending on the content of the element attributes
> "variant" & "style".

In your XSLT, you seem to be confusing *creating* an attribute in the
result (with xsl:attribute) with *testing* an attribute from the
source. You can do the latter with XPaths that look like '@variant' to
get the value of the variant attribute.

I think that you might want:

  <xsl:when test="@variant = 'Book'">
      <xsl:when test="@style = 'Fiction'">
        <xsl:apply-templates select="fiction" />
        <xsl:apply-templates select="non_fiction" />
  <xsl:when test="@variant = 'Graphic_Novel'>
    <xsl:apply-templates select="graphic_novel" />
  <xsl:when test="@variant = 'Magazine'>
    <xsl:apply-templates select="magazine" />

This assumes that your source XML looks something like:

<book variant="Book" style="Fiction">


<book variant="Magazine">

You'll note that I've changed:

  <xsl:for-each select="fiction">
    <xsl:apply-templates select="." />


  <xsl:apply-templates select="fiction" />

Since these do (almost) exactly the same thing. [The only difference
will be in the value of position() within the template matching the
fiction element, but I doubt that you're using the fact that it's
currently always 1.]



Jeni Tennison

 XSL-List info and archive:

Current Thread