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

Re: Fw:

Subject: Re: Fw:
From: "mohamed" <mohamed@xxxxxxxxx>
Date: Wed, 2 Feb 2000 15:41:33 -0500
name mohammed template
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

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.