Sergio Vilchis
Sergio Vilchis

Reputation: 322

XSLT 2.0 accessing attributes in hash map

I want to access a value of an attribute, but when I try to it doesn't output nothing. This is my xslt definition of the map.

<xsl:variable name="fieldsDataSources"> <entry key="PrintDate">new SimpleDateFormat("dd/MM/yyyy")</entry> <entry key="PrintTime">new SimpleDateFormat("HH:mm")</entry> <entry key="PageNumber">$V{PAGE_NUMBER}</entry> </xsl:variable>

And then this is how I call it.

<coso3><xsl:value-of select="$fieldsDataSources/entry[@key=@DataSource]"/></coso3> <coso><xsl:value-of select="$fieldsDataSources/entry[@key='PrintDate']"/></coso> <coso2><xsl:value-of select="@DataSource"/></coso2>

This is the output:

<coso3/> <coso>new SimpleDateFormat("dd/MM/yyyy")</coso> <coso2>PrintDate</coso2>

As you can see, I can't access the value of the enrty PrintDate using an attribute that contains the string PrintDate, I hope you can help me know how to access

Upvotes: 0

Views: 164

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167716

I suppose you want <coso3><xsl:value-of select="$fieldsDataSources/entry[@key = current()/@DataSource]"/></coso3>, assuming you want to compare the key attribute of the entry element to the DataSource of the outer context node (e.g. of a template or for-each).

In general I would suggest to define a key <xsl:key name="format" match="entry" use="@key"/> and then use <coso3><xsl:value-of select="key('format', @DataSource, $fieldsDataSources)"/></coso3>.

Upvotes: 1

Related Questions