473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1473
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Murtaza Tinwala | last post by:
Hi mates, I have the following problem in XSLT. I have following variables: ref-file = <path of XML document> eg "xmlDoc.xml" repeatpath = <a repeat path expressed in Xpath like /root/person >...
3
by: gimme_this_gimme_that | last post by:
I once downloaded a shareware program that allowed you to open an xml file, click on a text or an attribute, an then see the xpath expression that would fetch that data. The program didn't...
3
by: jose.jeria | last post by:
I have the following Code: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" indent="yes" encoding="UTF-8"/>...
7
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned...
5
by: ZUP_DUDE | last post by:
I'm looking for a way to Validate an XPath prior to executing the expression, without using a try catch clause. For example: I'm looking for something that would tell me that "\some/Xpath\to\Node"...
6
by: dotnetnoob | last post by:
i would like to know how i can build xpath expression dynamiclly. let's say i have a following xml file: <EventEnrollment InstanceNumber = "675"> <EventSource> <ObjectReference...
2
by: ajayreddy2105 | last post by:
Hi All, I want to build the xpath expression dynamically in the xsl for for-each. Scenario is like this:: 1. From javascript I am sending the parameters to xsl. 2. In xsl I am taking those...
2
by: arunairs | last post by:
Hi, Is there a way of validating and XPath? In this case , I am accepting an XPath from the user and I need to validate the XPath syntax. Is there a regular expression available that anyone can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.