[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Nestled


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:choose>
  <xsl:when test="@variant = 'Book'">
    <xsl:choose>
      <xsl:when test="@style = 'Fiction'">
        <xsl:apply-templates select="fiction" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="non_fiction" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:when>
  <xsl:when test="@variant = 'Graphic_Novel'>
    <xsl:apply-templates select="graphic_novel" />
  </xsl:when>
  <xsl:when test="@variant = 'Magazine'>
    <xsl:apply-templates select="magazine" />
  </xsl:when>
  <xsl:otherwise>Error</xsl:otherwise>
</xsl:choose>

This assumes that your source XML looks something like:

<book variant="Book" style="Fiction">
  <fiction>...</fiction>
</book>

or:

<book variant="Magazine">
  <magazine>...</magazine>
</book>

You'll note that I've changed:

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

into:

  <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.]

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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



Current Thread
Keywords