Subject: RE: [xsl] Establishing Defaults for Omitted Elements From: "Michael Kay" <mhk@xxxxxxxxx> Date: Wed, 3 Mar 2004 18:11:57 -0000 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Establishing Defaults for Omi, Dan Diebolt | Thread | Re: [xsl] Establishing Defaults for, David Carlisle |
[xsl] Establishing Defaults for Omi, Dan Diebolt | Date | Re: [xsl] Establishing Defaults for, David Carlisle |
Month |