[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] more elegant way to process element with default value
Hi all, I'm trying to set a (global) variable from a global-settings/setting element in my source XML document, but I want this variable to have a default value if the desired <setting> element doesn't exist. E.g. my XML source: <llcd:llc-display> <llcd:global-settings> <llcd:setting name="number-rows">false</setting> ... </llcd:global-settings> ... </llcd:llc-display> I want to set a number-rows variable in my stylesheet to /*/global-settings/setting[@name='number-rows'] but I want the variable to contain 'true' if such a <setting> node doesn't exist in the input document. I'm doing it like this so far: <xsl:variable name="number-rows"> <xsl:variable name="tmp" select="/*/llcd:global-settings/llcd:setting[@name = 'number-rows']" /> <xsl:choose> <xsl:when test="$tmp"><xsl:value-of select="$tmp" /></xsl:when> <xsl:otherwise><xsl:value-of select="'true'" /></xsl:otherwise> </xsl:choose> </xsl:variable> But that seems pretty verbose. And it will be worse as I have multiple settings variables with various names. Is there a more elegant way? (You may ask why I don't put the value 'true' in an attribute and just set a default for it in the DTD. The reason is that some settings will have values that must be arbitrary text, and my understanding is that certain kinds of character data cannot be stored in attribute values, since they are CDATA not PCDATA. Am I mistaken about this?) Thanks, Lars XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|