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

RE: rearranging and colouring a document

Subject: RE: rearranging and colouring a document
From: "Jacoby, Peter R." <PJACOBY@xxxxxxxxxxxx>
Date: Tue, 30 Jul 2002 15:46:53 -0400
xml colours
Horst,

As you said there are two parts to your problem, sorting and adding a colour
attribute.  The first is simpler, using the <xsl:sort> element:

<xsl:apply-templates select="sp">
	<xsl:sort select="speaker" data-type="text" order="ascending" />
</xsl:apply-templates>

This will match on all <sp> elements and they will be sorted by the text in
the <speaker> element.

For the second part, you were not exactly clear on the format for storing
the possible colours to use so I took some liberty.  You can create a
separate document to store all possible colours you will use.  In order for
this method to work, you must have enough colours listed (equal to or more
than the number of unique <person> elements).

The contents of possibleColours.xml:
<?xml version="1.0" ?>
<colours>
	<colour>red</colour>
	<colour>blue</colour>
	<colour>green</colour>
</colours>

You can then use the document function to retrieve the contents of this
file:
<xsl:variable name="colours"
select="document('possibleColours.xml')/colours"/>

The way you match a colour with a unique person is up to you, but one
possibility is to use the position of the colour element and the text after
"person" in the speaker element (i.e. "person2" would match on the colour in
the second position).

The entire stylesheet is:

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

<xsl:variable name="colours"
select="document('possibleColours.xml')/colours"/>

<xsl:template match="text">
	<text>
		<xsl:apply-templates select="sp">
			<xsl:sort select="speaker" data-type="text"
order="ascending" />
		</xsl:apply-templates>
	</text>
</xsl:template>

<xsl:template match="sp">
	<xsl:param name="current" select="substring-after(speaker,
'person')" />
	<sp colour="{$colours/colour[position() = $current]}">
		<xsl:copy-of select="*|text()" />
	</sp>
</xsl:template>

<xsl:template match="text()"/>
	
</xsl:stylesheet>

Hope this helps.

-Peter 

[I hadn't realized how hard it is for an American to write colour instead of
color repeatedly.  And my spell checker complained too.]


 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.