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

Many sets of eyes ...

Subject: Many sets of eyes ...
From: Curtis Burisch <burisch@xxxxxxxxxxx>
Date: Mon, 11 Feb 2002 15:49:56 +0000
sets of eyes
Hi,

A few days ago I had a problem to solve and was tempted to take it to 
the list but decided to grit my teeth and just get on with it. I'm 
still pretty new to XSLT so I'm afraid I've probably made some gaffes 
in my solution. I was hoping that the trained eyes on the list (e.g. 
the Uber-Deities Jeni, Michael, Jim, et. al) can give me some pointers 
on stylistic / performance issues? And of course help me point out 
gaffes ;-)

Given the xml source:

<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<wrap>
<joe>Apples</joe>
</wrap>
<wrap>
<joe>Bananas</joe>
</wrap>
<wrap>
<ann>Pears</ann>
</wrap>
<wrap>
<joe>Oranges</joe>
</wrap>
</root>

And the desired output:

Joe says: "Apples, Bananas."
Ann says: "Pears."
Joe says: "Oranges."

My implementation is:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text" encoding="ISO-8859-1" indent="no"/>
<xsl:strip-space elements="*"/>

<xsl:template match="root">
<xsl:for-each select="wrap">

<xsl:if test="name(preceding-sibling::*[position()=1]/*) != name(./*)">

<xsl:if test="name(./*[1])='joe'">
<xsl:text>Joe says: "</xsl:text>
</xsl:if>
<xsl:if test="name(./*[1])='ann'">
<xsl:text>Ann says: "</xsl:text>
</xsl:if>
</xsl:if>

<xsl:if test="joe">
<xsl:apply-templates select="joe"/>
</xsl:if>
<xsl:if test="ann">
<xsl:apply-templates select="ann"/>
</xsl:if>

<xsl:if test="name(following-sibling::*[position()=1]/*) = name(./*)">
<xsl:text>, </xsl:text>
</xsl:if>

<xsl:if test="name(following-sibling::*[position()=1]/*) != name(./*)">

<xsl:text>."&#x000A;</xsl:text>
</xsl:if>

</xsl:for-each>
</xsl:template>

<xsl:template match="joe">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="ann">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>


I chose to put Joe and Ann into templates because the actual 
application I am writing requires more complex processing for each 
different node type. But this example matches the real situation fairly 
closely ...

Thanks,
Curtis.

-- 

 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.