This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Fw:
- To: <xsl-list at mulberrytech dot com>
- Subject: Re: Fw:
- From: "mohamed" <mohamed at b-bop dot com>
- Date: Wed, 2 Feb 2000 15:41:33 -0500
- References: <020601bf6cf3$f419af80$0701000a@ebop.com> <38979717.A5FB4806@sas.upenn.edu>
- Reply-To: xsl-list at mulberrytech dot com
Thanks Steve, I like your solution a lot but for some reason it's giving me
a
java.net.MalformedURLException: : java.lang.StringIndexOutOfBoundsException:
String index out of range: 0
at this line
> <xsl:element name="{document('')/*/xsl:template[@name='attr-map']
> /map[@attr=name($attr-set[1])]/@elem}">
any ideas?
----- Original Message -----
From: Steve Tinney <stinney@sas.upenn.edu>
To: <xsl-list@mulberrytech.com>
Sent: Tuesday, February 01, 2000 9:31 PM
Subject: Re: Fw:
> > mohamed wrote:
> >
> > 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>
>
> Here is a version which marries recursion and an in-sheet map of
> attribute names to element names to produce something which is a bit
> funky to read, but very easy to maintain if you have a 1:1 correlation
> of attribute names to elements---you just add entries to the map.
>
> Steve
>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:output method="html" indent="yes"/>
>
> <xsl:template name="attr-map">
> <map attr="bold" elem="b"/>
> <map attr="italic" elem="i"/>
> </xsl:template>
>
> <xsl:template match="/">
> <xsl:apply-templates/>
> </xsl:template>
>
> <xsl:template match="testText/text">
> <xsl:call-template name="format-by-attribute"/>
> </xsl:template>
>
> <xsl:template name="format-by-attribute">
> <xsl:param name="attr-set" select="@*[.='yes']"/>
> <xsl:variable name="nattr" select="count($attr-set)"/>
> <xsl:choose>
> <xsl:when test="$nattr = 0">
> <xsl:apply-templates/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:element name="{document('')/*/xsl:template[@name='attr-map']
> /map[@attr=name($attr-set[1])]/@elem}">
> <xsl:choose>
> <xsl:when test="$nattr = 1">
> <xsl:apply-templates/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:call-template name="format-by-attribute">
> <xsl:with-param name="attr-set"
> select="$attr-set[position()>1]"/>
> </xsl:call-template>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:element>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
> </xsl:stylesheet>
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list