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

Re: decorator / wrapper design pattern

Subject: Re: decorator / wrapper design pattern
From: JBryant@xxxxxxxxx
Date: Fri, 18 Mar 2005 09:04:24 -0600
wrapper design pattern
Assuming your output is HTML, the easiest solution to this is a CSS 
stylesheet. However, in XSL, the easiest way to do it is simply to use 
apply-templates and literal result elements, thus:

<xsl:template match="section">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="title">
  <h1 style="font-style: italic"><xsl:apply-templates/></h1>
</xsl:template>

<xsl:template match="paragraph">
  <p style="font-style: italic"><xsl:apply-templates/></p>
</xsl:template>

Perhaps I could help more if you told me what you are really trying to do. 
In HTML, you can nest elements or apply multiple styles through CSS, so I 
guess you are not writing HTML as your output. What is your actual desired 
output?

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)




"Schaik, L.B. van" <L_B_van_Schaik@xxxxxxxxxxxxxxxxxxxxx> 
03/18/2005 07:37 AM
Please respond to
xsl-list@xxxxxxxxxxxxxxxxxxxxxx


To
<xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
cc

Subject
 decorator / wrapper design pattern






Hi,

I'm using XSL version 1.0 and am trying to use the decorator design
pattern, but can't get it to work in XSL.
Here is what I try to achieve:
Different types of elements all need to be surrounded by the same text.
For example:

I've XML:
<base>
  <section>
     <title>the title</title>
     <paragraph>some text</paragraph>
     <paragraph>more text</paragraph>
  </section>
  <section>
     <title>the title</title>
     <paragraph>other text</paragraph>
     <paragraph>more other text</paragraph>
     <paragraph>and more text</paragraph>
  </section>
</base>

Now I want all text in titles and in paragraphs to be italic and in
titles also to be bold.
My first thought was to use call-template like this:
<xsl:template match="title">
  <xsl:call-template name="bold">
    <xsl:call-template name="italic">
       <xsl:value-of select="."/>
    </xsl:call-template>
  </xsl:call-template>
</xsl:template>

But this is not the way to do this.
I cannot however figure out or find the solution. The decoration that
must be applied is much more complicated than bold or italic, but that
is besides the point, I think.
Here is my second try, but here is the problem that I cannot nest
decorators, so bold and italic is not possible on the same element:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="/">
  <xsl:call-template name="body"/>
</xsl:template>

<xsl:template match="section">
  <xsl:apply-templates />
  <br/>
</xsl:template>

<xsl:template match="title">
  <xsl:call-template name="bold" />
  <br/>
</xsl:template>

<xsl:template match="paragraph">
  <xsl:call-template name="italic" />
</xsl:template>

<xsl:template name="bold">
  <b>
     <xsl:apply-templates/>
  </b>
</xsl:template>

<xsl:template name="italic">
  <i>
     <xsl:apply-templates/>
  </i>
</xsl:template>

<xsl:template name="body">
  <html>
    <body>
      <xsl:apply-templates />
    </body>
  </html>
</xsl:template>

</xsl:stylesheet>


Can anybody give me a pointer?

Thanks in advance

Lucas

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.