Project

Profile

Help

xpath return values and empty element

Added by Anonymous about 19 years ago

Legacy ID: #3028486 Legacy Poster: Guillaume VIRANTIN (virantin)

Hello, Let's say I have a nillable element <toto> whose value is set through an XPATH formula. How can I get in the output an empty element <toto/> ? Do I have to go through a set of xsl statements (if or choose) ? Can't XPATH formula return the equivalent of a null ? Also, with fields mapped one to one : <tata><xsl:value-of select="titi"/></tata> If tata is of type decimal and titi is missing, what should I get ? (I can not really test it since I am using SAXON A...) G.


Replies (6)

Please register to reply

RE: xpath return values and empty element - Added by Anonymous about 19 years ago

Legacy ID: #3028546 Legacy Poster: Michael Kay (mhkay)

If the XPath expression EXP returns an empty sequence, then <a><xsl:value-of select="EXP"/></a> will return the empty element <a/>. Is this what you had in mind? If the required type of <a> is xs:decimal, and you attempt validation, then validation will fail unless (a) the schema describes element a as nillable, and (b) you generate it with an xsi:nil attribute. The xsi:nil attribute won't be added automatically. Michael Kay

RE: xpath return values and empty element - Added by Anonymous about 19 years ago

Legacy ID: #3028680 Legacy Poster: Guillaume VIRANTIN (virantin)

Hi Mike, As awlays...thank you for helping ! My case is a very simple one where I want to map one element to another. In an XPATH formula like the following, what could I use for ELSE-EXP "if b then b else ELSE-EXP" ,so that I can get a valid decimal empty element ? Setting a nil attribute would have to be done out of the XPath formula and would complexify the formula while what I want to do is very simple : if b => <a>value-of b</a> else => <a/> Thank you very much. G.

RE: xpath return values and empty element - Added by Anonymous about 19 years ago

Legacy ID: #3028758 Legacy Poster: Michael Kay (mhkay)

You can write an empty sequence explicitly as (), but in this case I don't think you need to. The expression if PATH then PATH else () is equivalent to the expression PATH Michael Kay

RE: xpath return values and empty element - Added by Anonymous about 19 years ago

Legacy ID: #3028894 Legacy Poster: Guillaume VIRANTIN (virantin)

This is however not a valid decimal... It seems to me that the only way is to write a tedious statement such as : <xsl:choose> <xsl:when test="b"> <a><xsl:value-of select="b"/></a> </xsl:when> <xsl:otherwise> <a> <xsl:attribute name="xsi:nil" select="'true'"/> </a> </otherwise> </xsl:choose>

RE: xpath return values and empty element - Added by Anonymous about 19 years ago

Legacy ID: #3029089 Legacy Poster: Michael Kay (mhkay)

Yes, if you want the xsi:nil it has to be explicit (personally I don't see the value of "nillable" and prefer to define the type as a list of 0 or 1 decimals). But you can abbreviate it to <xsl:variable name="nil" as="attribute()"> <xsl:attribute name="xsi:nil">true</xsl:attribute> </xsl:variable> <a><xsl:sequence select="(b, $nil)[1]"/></a> Michael Kay

RE: xpath return values and empty element - Added by Anonymous about 19 years ago

Legacy ID: #3029110 Legacy Poster: Guillaume VIRANTIN (virantin)

Wowww ! This is quite elegant ! Thank you for your input... G

    (1-6/6)

    Please register to reply