Create XPath expression dynamically

Discussion in 'XML' started by FaensenD@rki.de, Sep 22, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. Joris Gillis Guest

    Hi,

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

    > 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
    Joris Gillis, Sep 22, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,283
  2. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,964
    jan V
    Jul 29, 2005
  3. Alastair Cameron
    Replies:
    1
    Views:
    7,391
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  4. Anna
    Replies:
    0
    Views:
    519
  5. GIMME
    Replies:
    3
    Views:
    11,942
    vforvikash
    Dec 29, 2008
Loading...

Share This Page