Create XPath expression dynamically

F

FaensenD

Consider the following XML document

<root>
<PersonStreet>24 Miller Street</PersonStreet>
<PersonZIP>12345</PersonZIP>
<PersonCity>Munich</PersonCity>
<CompanyStreet>24 Miller Street</CompanyStreet>
<CompanyZIP>12345</CompanyZIP>
<CompanyCity>Munich</CompanyCity>
</root>

In a template I want to access the nodes that are prefixed by a given
parameter.

The following doesn't work but should illustrate what I mean.

<xsl:template name="address">
<xsl:param name="prefix/>

<xsl:element name="{$prefix}">
<xsl:value-of select=$prefix + "Street" />
<xsl:value-of select=$prefix + "ZIP" />
<xsl:value-of select=$prefix + "City" />
</xsl:element>

</xsl:template>

Is it possible to create such an XPath expression dynamically?

Thank you

Daniel Faensen
 
J

Joris Gillis

Hi,

Tempore 14:07:33 said:
The following doesn't work but should illustrate what I mean.

<xsl:template name="address">
<xsl:param name="prefix/>

<xsl:element name="{$prefix}">
<xsl:value-of select=$prefix + "Street" />
<xsl:value-of select=$prefix + "ZIP" />
<xsl:value-of select=$prefix + "City" />
</xsl:element>

</xsl:template>

Is it possible to create such an XPath expression dynamically?
No it is not.
You can however, work around it:

<xsl:value-of select="*[local-name()=concat($prefix,'City')]" />


regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top