469,582 Members | 2,425 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,582 developers. It's quick & easy.

Create XPath expression dynamically

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

Sep 22 '05 #1
1 1391
Hi,

Tempore 14:07:33, die Thursday 22 September 2005 AD, hinc in foro {comp.text.xml} scripsit <Fa******@rki.de>:
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,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
«Error, keyboard not found— press F1 to continue» , BIOS
Sep 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by gimme_this_gimme_that | last post: by
3 posts views Thread by jose.jeria | last post: by
7 posts views Thread by Ot | last post: by
5 posts views Thread by ZUP_DUDE | last post: by
6 posts views Thread by dotnetnoob | last post: by
2 posts views Thread by ajayreddy2105 | last post: by
2 posts views Thread by arunairs | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.