You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Stanley Santiago <st...@sun.com> on 2000/08/10 09:16:57 UTC

Dynamic Xpath Question....

Hi,

I have a situation where I need to traverse the tree of a -source- xml
doc based on
the  value of an attribute found in -another- xml doc.

Consider this rather simplistic example.....


Content.xml         ---  Contains form data
-------------
<Form>
     <UserId>
            <Name>uid</Name>
            <Value>someguy</Value>
     </UserId>
</Form>


Source.xml            ---- Source doc contains a Xpath expression as an
attribute Value
-------------
<Html xmlns:template="www.zombie.com" >
    <Input type="text"  template:use-attribute="name,
/Form/UserId/Name/text()" />
</Html>


Transformed Source.xml            ---- The -name- attribute/value pair
needs to be created
                                                         using the Xpath
in Source.xml but applied on Content.xml
-------------------------

<Html  >
    <Input type="text"  name="uid" value="someguy" />
</Html>


StyleSheet snippet
-------------------

<xsl:variable name="content" select="document('Content.xml')" />
......
......
<xsl:template match="*[@template:use-attribute]">

        <xsl:variable name="attr" select="./@template:use-attribute" />

        <xsl:variable name="path"  select="substring-after($attr,',')"
/>

     QUESTION:    $path value at this point is  " /Form/UserId/Name",
how do we
                              use $path to traverse Content.xml   ?
Basically, is it possible
                                generate XPath expressions dynamically ?

TIA,
Stan