Subject: Re: Fw: From: "mohamed" <mohamed@xxxxxxxxx> Date: Wed, 2 Feb 2000 15:41:33 -0500 |
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@xxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxx> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Fw:, Steve Tinney | Thread | paragraph style problem, ravi akireddy |
XSLT processing corrupts character , Christian Mallwitz | Date | Re: parse using DOM, Warren Hedley |
Month |