Subject: [xsl] Re: Establishing Defaults for Omitted Elements From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx> Date: Wed, 3 Mar 2004 21:51:01 +0100 |
Use: *[name() = $velName] | $vDefaults [not(current()/*[name()=$velName])] /* [name() = $velName] Cheers, Dimitre Novatchev FXSL developer http://fxsl.sourceforge.net/ -- the home of FXSL Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html "Dan Diebolt" <dandiebolt@xxxxxxxxx> wrote in message news:20040303172920.75271.qmail@xxxxxxxxxxxxxxxxxxxxxxxxxx > 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 -> |
---|---|---|
Re: [xsl] Establishing Defaults for, David Carlisle | Thread | [xsl] Establishing Defaults for Omi, Dan Diebolt |
Re: [xsl] Establishing Defaults for, David Carlisle | Date | [xsl] [REMINDER] CFP: First Interna, Lionel Villard |
Month |