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

RE:

Subject: RE:
From: "Carl Soane" <csoane@xxxxxxxxxxxxx>
Date: Tue, 1 Feb 2000 18:09:01 -0800
RE:
Here's a god-awful way of doing it using some recursion.  Hopefully somebody
else will give you a more elegant solution to the problem:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/TR/REC-html40">

<xsl:output method="html"/>

<xsl:template match="/">
 <xsl:apply-templates select="testText/text"/>
</xsl:template>

<xsl:template match="testText/text">
 <xsl:call-template name="formatter"><xsl:with-param
name="current">1</xsl:with-param></xsl:call-template>
</xsl:template>

<xsl:template name="formatter">
 <xsl:param name="current"/>
 <xsl:choose>
  <xsl:when test="$current &lt; 2">
   <xsl:choose>
		<xsl:when test="@bold='yes'">
		 <b>
      <xsl:call-template name="formatter"><xsl:with-param
name="current">2</xsl:with-param></xsl:call-template>
    </b>
	  </xsl:when>
		<xsl:otherwise>
      <xsl:call-template name="formatter"><xsl:with-param
name="current">2</xsl:with-param></xsl:call-template>
		</xsl:otherwise>
	 </xsl:choose>
 </xsl:when>

  <xsl:when test="$current &lt; 3">
   <xsl:choose>
	  <xsl:when test="@italic='yes'">
		 <i>
      <xsl:call-template name="formatter"><xsl:with-param
name="current">3</xsl:with-param></xsl:call-template>
    </i>
	  </xsl:when>
		<xsl:otherwise>
      <xsl:call-template name="formatter"><xsl:with-param
name="current">3</xsl:with-param></xsl:call-template>
		</xsl:otherwise>
	 </xsl:choose>
 </xsl:when>
 <xsl:otherwise>
  <xsl:value-of select="text()"/>
 </xsl:otherwise>
 </xsl:choose>
</xsl:template>

</xsl:stylesheet>

-----Original Message-----
From:	owner-xsl-list@xxxxxxxxxxxxxxxx [SMTP:owner-xsl-list@xxxxxxxxxxxxxxxx]
On Behalf Of mohamed
Sent:	Tuesday, February 01, 2000 12:36 PM
To:	xsl
Subject:	Fw:

I'm trying to call templates based on attribute names:
?
<?xml version="1.0"?>
?<testText >
???? <text bold="yes">WITH BOLD</text>
???? <text bold="yes" italic="yes"> WITH BOLD AND ITALIC</text>
?</testText>

so I declared templates that are called and?match bold and italics,
?
?<xsl:template match="bold" name="bold">
? <b>
??? <xsl:apply-templates/>
</b>
</xsl:template>
?
<xsl:template match="italics" name="italics">
? <i>
??? <xsl:apply-templates/>
</i>
</xsl:template>
?
and I want to get an output as follows:
<b>WITH BOLD</b>
<b><i>WITH BOLD AND ITALIC</i></b>
?
?but because the
<xsl:apply-templates match=""> and the
<xsl:call-template name=""> don't evaluate expressions (like a variable $att
whose value is bold, or the name() function that returns the name of the
attribute) within the match and the name attributes I couldn't call the
templates!
I don't know how many attributes I'll have (bold, italics, small, .... etc)
so I want to make it flexible enough so adding one more attribute requires
just adding a new template that matches it.
?
any suggestions?!
?
thanks ........
?
----------------------------------
?
Mohamed Abdelrahman


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


Current Thread
  • Fw:
    • mohamed - Tue, 1 Feb 2000 15:35:31 -0500
      • Carl Soane - Tue, 1 Feb 2000 18:09:01 -0800 <=
      • Steve Tinney - Tue, 01 Feb 2000 21:31:51 -0500

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.