Re: [xsl] Re: Conditional XSL Variable

Subject: Re: [xsl] Re: Conditional XSL Variable
From: "Darcy Parker" <darcyparker@xxxxxxxxx>
Date: Thu, 20 Nov 2008 14:58:37 -0500
One problem I see is that
<xsl:value-of select="$lookupTable/map:table/map:otherwise"/>
will output an empty string because
"$lookupTable/map:table/map:otherwise"
has no text() node in it.  Perhaps you meant:
<xsl:value-of select="$lookupTable/map:table/map:otherwise/@codeB"/>

Similarly
<xsl:value-of select="$lookupTable/map:table/map:entry[@codeA=$valueOfCodeA]" />
will output an empty string.
Perhaps you meant
<xsl:value-of select="$lookupTable/map:table/map:entry[@codeA=$valueOfCodeA][1]/@codeB"
/>

You should also try putting <xsl:message><value-of
select="$valueofCodeA"/></xsl:message> in for debugging purposes in
case $valueofCodeA is different than what you expected.

Darcy

On Thu, Nov 20, 2008 at 2:51 PM, raulvk <raulvk.soa@xxxxxxxxx> wrote:
>
> Just to give some more information: I am using the oXygen XSLT
> Debugger, and it looks like the variable $mappingsCodeA is never even
> assigned a value or initialised!
>
> Any clues?
>
> 2008/11/20 raulvk <raulvk.soa@xxxxxxxxx>:
> > Hi everyone,
> >
> > I am using XSLT 2.0 to transform from one XML document to another.
> >
> > I have defined a lookup table embedded in an XSL variable, which is
> > used within the template and is defined as a global variable similar
> > to the following:
> >
> >    <xsl:variable name="lookupTable">
> >        <map:table>
> >            <map:entry codeA="90434" codeB="9801" codeC="0121" />
> >            <map:entry codeA="90437" codeB="1800" codeC="1212" />
> >            <map:otherwise codeB="9800" codeC="9999" />
> >        </map:table>
> >    </xsl:variable>
> >
> > Functionally, this table will be looked up based on codeA, and the
> > corresponding values of codeB and codeC will be inserted in different
> > elements within the resulting XML document.
> > However, if the received value does not match any of the specified
> > codeA values, the "otherwise" node should be used instead.
> >
> > I have created a variable that will store the node that will be used
> > to obtain the codeB and codeC variables.
> >
> >                <xsl:variable name="mappingsCodeA">
> >                        <xsl:choose>
> >                            <xsl:when
> > test="count($lookupTable/map:table/map:entry[@codeA=$valueOfCodeA]) =
> > 1">
> >                                <xsl:value-of
> > select="$lookupTable/map:table/map:entry[@codeA=$valueOfCodeA]" />
> >                           </xsl:when>
> >                            <xsl:otherwise>
> >                                <xsl:value-of
> > select="$lookupTable/map:table/map:otherwise"/>
> >                            </xsl:otherwise>
> >                    </xsl:choose>
> >               </xsl:variable>
> >
> > (where $valueOfCodeA is a variable that has the value that has to be looked up).
> >
> > However, I am finding that the variable $mappingsCodeA never contains
> > anything. I think it has something to do with the type of the
> > variable, because it is not initialised as a result-tree fragment.
> >
> > Has anyone come across this problem before? By the way, I am using
> > Saxon-B 9.1.0.3.
> >
> > Thanks!

Current Thread