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

Re: attributes to nested element problem

Subject: Re: attributes to nested element problem
From: George Cristian Bina <george@xxxxxxx>
Date: Wed, 19 May 2004 09:36:57 +0300
xslt nested elements
Hi,

You can use a template for each condition that triggers the generation of an element. The role of each such template will be to check its condition and emit the element to the output if the condition is met and in either case it will do some other processing required at that stage and then delegate to the template that checks the next condition.

In your case you can have a template to check if the paragraph element should be present, a template for bold and a template for italic.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="label">
<xsl:call-template name="checkParagraph"/>
</xsl:template>
<xsl:template name="checkParagraph">
<xsl:choose>
<xsl:when test="@paragraph='true'">
<p>
<span>
<xsl:copy-of select="@align"/>
<xsl:call-template name="checkBold"/>
</span>
</p>
</xsl:when>
<xsl:otherwise>
<span>
<xsl:copy-of select="@align"/>
<xsl:call-template name="checkBold"/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkBold">
<xsl:choose>
<xsl:when test="@bold='true'">
<b>
<xsl:call-template name="checkItalic"/>
</b>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="checkItalic"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="checkItalic">
<xsl:choose>
<xsl:when test="@italic='true'">
<b>
<xsl:value-of select="."/>
</b>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>


Hope that helps,
 George
-----------------------------------------------
George Cristian Bina
<oXygen/> XML Editor & XSLT Editor/Debugger
http://www.oxygenxml.com


Tim Lord wrote:
Hi,

I was wondering how to convert an element:

<label align="left" paragraph="true" italic="true" bold="true">This is a label</label>

Into this html:

<p><span align="left"><b><i>This is a label</i></b></span></p>

I found solutions to converting attributes to elements but what about nested elements like this?

Cheers,

/tim

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.