XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Paul MedinaSubject: descriptive? node
Author: Paul Medina
Date: 23 Feb 2007 09:48 PM
Hi all,

I've been struggling with an XSLT project. I've got the basics down but I'm having trouble with the following XML to HTML conversion.

Sample XML

<document>
<item>
<pardef id="1" leftmargin="1in"/>
<par def="1">
<run>
<font style="italic" color="blue" size="8pt"/>
some text 1
</run>
</par>
<par>
<run>
<font weight="bold" size="8pt"/>
some text 2
</run>
</par>
<pardef id="2" align="center"/>
<par def="2">
<run>
<font size="8pt"/>
some text 3
</run>
</par>
<par def="1">
<run>
<font size="8pt" color="red"/>
some text 4
</run>
</par>
</item>
</document>


Each pardef node sets up a definition for each par node that has the same def attribute value as the matching pardef id attribute value and any subsequent par node without a def attribute up until either another pardef node or a par def="x" node is encountered.

So in the above xml the par def="2" node should be centered when converted to HTML then the following par def="1" node should have a left margin of "1in" as specified in the pardef id="1" descriptive node.

I tried capturing the id of a pardef node in a variable and then comparing each par that I came across. I would apply the attributes to each par node up until either the def id attribute changed or another pardef node was encountered . This would seem to work but unforutenately xsl:variable can't be re-assigned. The stylesheet I tried is below. It should produce the following HTML:

<span style="margin-left: 10px; font-size:8pt; font-style:italic; color:blue;">
some text 1
</span><p/>
<span style="margin-left: 10px; font-size:8pt; font-weight:bold;">
some text 2
</span><p/>
<span style="text-align: center; font-size:8pt;">
some text 3
</span><p/>
<span style="margin-left: 10px font-size:8pt;">
some text 4
</span>


I'd appreciate it if anyone can provide some insight.

Thanks.

stylesheet snippet

<xsl:variable name="parDefNodes" select="//pardef"/>

<xsl:for-each select="document/item/par">
<span>
<xsl:choose>
<xsl:when test="@def">
<xsl:variable name="id" select="@def"/>
<xsl:for-each select="$parDefNodes">
<xsl:if test="$id=@id">
<xsl:attribute>
<xsl:if test="@align">
assign attribute
</xsl:if>
.
.test for other attributes
.
</xsl:attribute>
</xsl:if>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates match="run"/>

</span>
</xsl:for-each>
.
.
.

the run template handles the application of the font attributes and outputs the par node content.






Posttop
(Deleted User) Subject: descriptive? node
Author: (Deleted User)
Date: 26 Feb 2007 08:41 AM
Hi Paul,
this is a generic XSLT question, but this is a support forum for Stylus Studio; you can get better answers on a XSLT mailing list like the one run by Mulberry Tech.

Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.