xsl-list
[Top] [All Lists]

[xsl] XSL String Mapping Problem.

2008-12-10 05:21:18
Hello,

I am looking for a very nice mapper  "Design Pattern".

I used the XML/XSL snippet below. However the "@key eq ." seems not to work.

If I introduce a variable it works fine:

    <xsl:variable name="var" select="."/>
    <xsl:value-of select="$map[(_at_)key eq $var]/@val"/>

Questions:

1. How to get this mapper working without variable?
2. What is the the 'defacto XPath standard' for mapping  a list
hardcoded keys to hardcoded values?

Thanks, Jos

<demos>
    <demo><keyAttr>key1</keyAttr></demo>
    <demo><keyAttr>key2</keyAttr></demo>
</demos>


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >
    <xsl:variable name="map" as="element()+">
      <elem key="key1" val="value1"/>
      <elem key="key2" val="value2"/>
      <elem key="key3" val="value3"/>
    </xsl:variable>
<xsl:template match="demos/demo">
    Found key: <xsl:value-of select="."/>
    Corresponding value: <xsl:value-of select="$map[(_at_)key eq .]/@val"/>
    <br/>
</xsl:template>
</xsl:stylesheet>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>