Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Create XPath expression dynamically

Reply
Thread Tools

Create XPath expression dynamically

 
 
FaensenD@rki.de
Guest
Posts: n/a
 
      09-22-2005
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">
<xslaram 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

 
Reply With Quote
 
 
 
 
Joris Gillis
Guest
Posts: n/a
 
      09-22-2005
Hi,

Tempore 14:07:33, die Thursday 22 September 2005 AD, hinc in foro {comp.text.xml} scripsit <(E-Mail Removed)>:

> The following doesn't work but should illustrate what I mean.
>
> <xsl:template name="address">
> <xslaram 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments