Subject: RE: [xsl] Nestled <xsl:choose> From: "Michael Kay" <mhkay@xxxxxxxxxxxx> Date: Sat, 14 Jul 2001 09:47:36 +0100 |
Try to avoid deeply nested conditionals: that's what template rules are for. Write a template rule for each of the separate conditions you want to process. Your code will be far more maintainable. Mike Kay Software AG > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of dante > Sent: 14 July 2001 08:16 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] Nestled <xsl:choose> > > > I'm trying to create a testing structure to assign a > different template > depending on the content of the element attributes "variant" > & "style". > in pseudo code: > --------------------------------- > if variant = book > then > if style = fiction > use fiction template > else > use non-fiction template > endif > elseif variant = graphic novel > use graphic novel template > elseif variant = magazine > use magazine template > else > show error massage > endif > --------------------------------- > Is this possible in xsl? > Or should I create a separate template to test the "fiction" > attribute. > > Here's the xsl code that I'm using. > <!--CHECK VARIANT--> > <xsl:attribute name="variant"> > <xsl:choose> > <!--BOOK VARIANT--> > <xsl:when test="variant = 'Book'"> > <!--CHECK STYLE--> > <xsl:attribute name="style"> > <xsl:choose> > <!--FICTION STYLE--> > <xsl:when test="style = 'Fiction'"> > <xsl:for-each select="fiction"> > <xsl:apply-templates select="." /> > </xsl:for-each> > </xsl:when> > <!--END FICTION STYLE--> > <!--NON-FICTION STYLE--> > <xsl:otherwise> > <xsl:for-each select="non-fiction"> > <xsl:apply-templates select="." /> > </xsl:for-each> > </xsl:otherwise> > <!--END NON-FICTION STYLE--> > </xsl:choose> > </xsl:attribute> > <!--END CHECK STYLE--> > <!--END BOOK VARIANT--> > </xsl:when> > <!--GRAPHIC_NOVEL VARIANT--> > <xsl:when test="variant = 'Graphic_Novel'"> > <xsl:for-each select="graphic_novel"> > <xsl:apply-templates select="." /> > </xsl:for-each> > </xsl:when> > <!--END GRAPHIC_NOVEL VARIANT--> > <!--MAGAZINE VARIANT--> > <xsl:when test="variant = 'Magazine'"> > <xsl:for-each select="magazine"> > <xsl:apply-templates select="." /> > </xsl:for-each> > </xsl:when> > <!--END MAGAZINE VARIANT--> > <!--ERROR TRAP--> > <xsl:otherwise> > <xsl:text>Error</xsl:text> > </xsl:otherwise> > <!--END ERROR TRAP--> > </xsl:choose> > </xsl:attribute> > <!--END CHECK VARIANT--> > > Thanks, > Oliver > > p.s. does this list have a tip harvester or something similar? > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Nestled <xsl:choose>, Trevor Nash | Thread | Re: [xsl] Nestled <xsl:choose>, David Carlisle |
RE: [xsl] Using name() with XPath e, Michael Kay | Date | Re: [xsl] Nestled <xsl:choose>, David Carlisle |
Month |