RE: [xsl] need help with converting attribute into elements

Subject: RE: [xsl] need help with converting attribute into elements
From: Rod Humphris - FLPTN <rod.humphris@xxxxxxxxxxxxxx>
Date: Tue, 14 Oct 2003 11:19:33 +0100
Code nested choose/when/otherwise blocks to cover all the combinations that
you want to catch. It isn't pretty but it will work. Copy/paste will get you
there fast enough!

<xsl:template match="text">
 <p>
  <xsl:choose>
   <xsl:when test="@bold='true'">
    <b>
     <xsl:choose>
      <xsl:when test="@italic='true'">
       <i>
        <xsl:choose>
          <xsl:when test="@underline='true'">
           <u>
            <xsl:value-of select="."/>
          </u>
         <xsl:otherwise>
          <xsl:value-of select="."/>
        </xsl:otherwise>
       </xsl:choose>
       </i>
       </xsl:when>
       <xsl:otherwise>
        etc, etc....
    </b>
   </xsl:when>
   <xsl:otherwise>
  
   </xsl:otherwise> 
  </xsl:choose>
 </p>
</xsl:template>
There you are I've basically done it for you, just fill in the missing bits.

I can't myself think of a better way. I think perhaps that sometimes xslt
just is verbose and this may be one of them.

The best I can suggest is that you could write the code inside a named
template (look it up if you don't know) which takes an element as a
parameter and then at least you won't have to write it again and you can use
it on other elements besides a 'text' one. You could then xsl:include/import
it from a library xslt to make it more reusable again.

Ah just saw Jarno's. Much better. Take your pick.

Cheers

Rod

-----Original Message-----
From: Ale¹ Peregrin [mailto:ales.peregrin@xxxxxxxxxx]
Sent: 14 October 2003 10:49
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] need help with converting attribute into elements


Hi Rod,

thanx for your solution suggestion.
I'm not sure, wheter I understand it right. Does it mean to write it eight
times, once for each combinatoion of the atribute values, e.g. first for
"all true", than <otherwise> one of them false and so on? Or is there some
easier way? Could you please
write some more detailed example?

thanx

Ales Peregrin

----- Original Message -----
From: "Rod Humphris - FLPTN" <rod.humphris@xxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Tuesday, October 14, 2003 11:05 AM
X-Scanned: By Symantec Anti-Virus Scan Engine
Subject: Re: [xsl] need help with converting attribute into elements


> Hi Ales
>
> I expect someone could suggest a prettier and more modular approach but
> nested choose blocks would do it:
>
> <xsl:template match="text">
>  <p>
>   <xsl:choose>
>    <xsl:when test="@bold='true'">
>     <b>
>      <xsl:choose>
>       <xsl:when test="@italic='true'">
>        <i>
>          etc, etc.....
>     </b>
>    </xsl:when>
>    <xsl:otherwise>
>
>    </xsl:otherwise>
>   </xsl:choose>
>  </p>
> </xsl:template>
>
> Cheers
>
> Rod
>
>
> -----Original Message-----
> From: Ale¹ Peregrin [mailto:ales.peregrin@xxxxxxxxxx]
> Sent: 14 October 2003 09:47
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> X-Scanned: By Symantec Anti-Virus Scan Engine
> Subject: RE: [xsl] need help with converting attribute into elements
>
>
> Hi!
> I'm trying to make a XSLT stylexheet for transforming XML document into
HTML
> and there is a problem I'm unable to solve, even after a week of trying
and
> searching all over the internet. The problem looks quite easy to me and it
> seems I'm missing something important about XSL  language. Here it goes:
>
> I have an XML tag which looks like this: <text bold=true italic=true
> underline=false>Help!</text>
> In this case, the result in HTML should be:
> <font>
>    <b>
>       <i>
>          Help!
>       </i>
>    </b>
> </font>
>
> I simply need to transform the attributes into HTML elements so that any
of
> the possible combinations of the atributes' values would be transformed
> correctly.
>
> Can anyone help me?
> Thanx.
> Ales Peregrin
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
> ________________________________________________________________________
> This email has been scanned for all viruses by the MessageLabs Email
> Security System. For more information on a proactive email security
> service working around the clock, around the globe, visit
> http://www.messagelabs.com
> ________________________________________________________________________
>
>
> ________________________________________________________________
> Any opinions expressed in this email are those of the individual and not
necessarily the Company. Unless expressly stated to the contrary, this email
is not intended to give rise to a new, or affect an existing, contractual or
other legal relationship.This email and any files transmitted with it,
including replies and forwarded copies which may contain alterations)
subsequently transmitted from the Company, are confidential and solely for
the use of the intended recipient. The unauthorised use, disclosure or
copying of this email, or any other information contained or attached,is
prohibited and could, in certain circumstances, be a criminal offence.
>
> If you have received this email in error please notify the sender as soon
as possible.
>
> This footnote also confirms that this email message has been swept for the
presence of computer viruses.
>
> www.focusdiy.co.uk
> _________________________________________________________________
>
> ________________________________________________________________________
> This email has been scanned for all viruses by the MessageLabs Email
> Security System. For more information on a proactive email security
> service working around the clock, around the globe, visit
> http://www.messagelabs.com
> ________________________________________________________________________
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>



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


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

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


Current Thread