Altova Mailing List Archives


RE: [xsl] Establishing Defaults for Omitted Elements

From: "Michael Kay" <mhk@--------->
To:
Date: 3/3/2004 8:12:00 AM
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: [xsl] 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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.