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

RE: Establishing Defaults for Omitted Elements

Subject: RE: Establishing Defaults for Omitted Elements
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 3 Mar 2004 18:11:57 -0000
xml use when value
Try select="(a | $menuDefaults/a)[last()]"

This assumes the defaults are at the start of the file.

Michael Kay

# -----Original Message-----
# From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-
# list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Dan Diebolt
# Sent: 03 March 2004 17:29
# To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
# Subject:  Establishing Defaults for Omitted Elements
# 
# I have an XML configuration file for which I am defining the structure of
# (ie I
# can change it) and in relevant part currently looks like this:
# 
# <Items>
#  <Defaults>
#   <a>0</a>
#   <b>1</b>
#  </Defaults>
#  <Item>
#   <a>1</a>
#  </Item>
#  <Item>
#   <b>2</b>
#  </Item>
# </Items>
# 
# The <Defaults> element is intended to set the default value of elements
# <a> and
# <b> if these elements are absent in any of the subsequent <Item>'s.
# 
# When I process the <Item>'s and need to grab the value of <a> or <b>, I am
# currently using code like this:
# 
# 
# <xsl:template match="Item">
#  <xsl:variable name="Defaults" select="../Defaults"/>
# 
#  <!-- code use when value for <a> is needed -->
#  <xsl:choose>
#   <xsl:when test="a">
#    <xsl:value-of select="a"/>
#   </xsl:when>
#   <xsl:otherwise>
#    <xsl:value-of select="$MenuDefaults/a"/>
#   </xsl:otherwise>
#  </xsl:choose>
# 
#  <!-- code use when value for <a> is needed -->
#  <xsl:choose>
#   <xsl:when test="b">
#    <xsl:value-of select="b"/>
#   </xsl:when>
#   <xsl:otherwise>
#    <xsl:value-of select="$MenuDefaults/b"/>
#   </xsl:otherwise>
#  </xsl:choose>
# </xsl:template>
# 
# Could anyone offer a more compact way to implement a scheme like this
# (changing
# either the XML or the XSLT)? In the actual application I have 100's of
# elements
# like <a> and <b> and it is becoming a bit verbose to use the <xsl:choose>
# element in this fashion. The solution has to work with IE6. The most
# important
# feature I must retain is the ability to make hand editing of the XML
# configuration file as simple as possible (minimal typing, no attributes
# etc).
# There is currently no DTD or schema for the XML config file.
# 
# Any help would be appreciated.
# 
# 
# 
# 
# 
#  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 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.