This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE:
- To: <xsl-list at mulberrytech dot com>
- Subject: RE:
- From: "Carl Soane" <csoane at ix dot netcom dot com>
- Date: Tue, 1 Feb 2000 18:09:01 -0800
- Reply-To: xsl-list at mulberrytech dot com
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 < 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 < 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@mulberrytech.com [SMTP:owner-xsl-list@mulberrytech.com]
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