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

Re: Getting variable yet most immediate parentNode

Subject: Re: Getting variable yet most immediate parentNode
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Fri, 28 Sep 2007 19:33:59 +0200
Re:  Getting variable yet most immediate parentNode
David Carlisle wrote:
me>(@value,@name,.)[1]

wendell> ... and in XPath 1.0, you're forced into explicit testing, since wendell> attributes have no order in the data model.


or, if you must, (@value|@name[not(../@value)]|.)[last()] but perhaps's
that's "explicit testing". How explicit does something have to be to be
"explicit"?

And I always found XSLT 1.0 too verbose... this is nice and compact David!


But when this list of options gets longer, it might be better to add normal template matching and make the precedence explicit:

<xsl:apply-templates select="." mode="option-value" />
.......

<xsl:template match="option[@highervalue]" mode="option-value" priority="20">
<xsl:value-of select="@highervalue" />
</xsl:template>


<xsl:template match="option[@value]" mode="option-value" priority="10">
   <xsl:value-of select="@value" />
</xsl:template>

<xsl:template match="option[@name]" mode="option-value" >
   <xsl:value-of select="@name" />
</xsl:template>

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


The last two do not need a priority (generic match always has lower priority over a match with a predicate). Though this is by far more verbose then David statement, when you plan to add more and more xsl:if statements it will get messy (as you can see in your original post), using template matching you can keep the structure easy (i.e., not too nested) and you can focus on the rules instead of all possible scenarios. The scenarios are then automatically taken and chosen by the processor.


The nice thing, also, is how easy and clear it gets now for applying different styles (colors, fonts) to each of the options.

Cheers,
-- Abel Braaksma

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.