[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Nestled <xsl:choose>

Subject: Re: Nestled <xsl:choose>
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sat, 14 Jul 2001 09:15:22 +0100
Re:  Nestled <xsl:choose>
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.