[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Nestled <xsl:choose>
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: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|