Santhos
Santhos

Reputation: 3498

Using xsl template parameter as node in a select (of i.e. value-of element)

Imagine you have a xml file:

<dictionary>
    <row>
        <table>log</table>
        <entity>Log</entity>
    </row>

    <row>
        <table>mail_macros</table>
        <entity>MailMacro</entity>
    </row>
</dictionary>

And you want to write a generic template to obtain an element from the row:

<xsl:template name="row">
    <xsl:param name="pElement" />
    <xsl:value-of select="./dictionary/row/$pElement />
</xsl:template>

So when I call the template with pElement set to string 'table' it returns table values etc.

Is it possible to write such an expression in xslt 1.0? Because this one does not work.

Upvotes: 3

Views: 791

Answers (1)

Sean B. Durkin
Sean B. Durkin

Reputation: 12729

XPATH expressions don't work like that. You need ....

 <xsl:value-of select="./dictionary/row/*[local-name()=$pElement] />

Caveat

Assumes you are not using namespaces. Let us know if otherwise.

Upvotes: 3

Related Questions