Sunday, 15 September 2013

xml - Correct syntax for internal XSL map lookup -



xml - Correct syntax for internal XSL map lookup -

i have internally defined mapping table in xsl document , want access value using xpath xml key. in xsl2 led believe easy this, seem getting errors.

<xsl:variable name="map"> <entry key="one">testone</entry> <entry key="two">testtwo</entry> <entry key="three">testthree</entry> </xsl:variable> <xsl:variable name="testvariable"> <value-of select="$map/entry[@key=a/b]"/> </xsl:variable>

if xml document looks like:

<a> <b>three</b> <a>

testvariable in xsl document should resolve 'testthree'

you've got 2 problems here. firstly should xsl:value-of , not value-of

secondly, utilize a/b in xpath condition, relative entry element searching on, not a/b in original xml.

try instead:

<xsl:variable name="key" select="a/b"/> <xsl:variable name="testvariable"> <xsl:value-of select="$map/entry[@key=$key]"/> </xsl:variable>

or improve still, write this

<xsl:variable name="key" select="a/b"/> <xsl:variable name="testvariable" select="$map/entry[@key=$key]"/>

in fact, don't have utilize key variable @ all, utilize current() function current context in xml document

<xsl:variable name="testvariable" select="$map/entry[@key=current()/a/b]"/>

xml variables xslt xpath

No comments:

Post a Comment