364,007 Members | 1310 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Cand XSLT evaluate XPath in String variable?

Son KwonNam
P: n/a
Son KwonNam
In XSLT, is this possible to get value from xml using XPath
which is in XSLT variable?

I mean XPath strings can be dynamic while XSL Transforming.

If possible, How??

Because I'm not a native English speaker, it's quite hard
to make the problem clear. Please see the following example.

There are two XML files.
One has data, and the other has xpath. I will transform
the XPath XML.

for example,

* XPath XML
<xpaths>
<xpath>/students/student/name</xpath>
<xpath>/students/student/id</xpath>
</xpaths>

* Data XML : data.xml
<students>
<student>
<name>John Doe</name>
<id>234234</id>
</student>
</students>

* XSL snippet.
<xsl:template match="//xpath">
<xsl:variable name="xpathstring" select="."/>
<B>XPaht : <xsl:value-of select="$xpathstring"/></B>
<B>Value : <xsl:value-of select="document('data.xml')/$xpathstring" />
</B> </xsl:template>


As you know, that <xsl:value-of select(document(bla...)/> line
does not
work.

Any solution for this problem in XSLT?
I use JDOM/Xalan for transforming.

Thanks,
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


Joris Gillis
P: n/a
Joris Gillis
Hi,
[color=blue]
> In XSLT, is this possible to get value from xml using XPath
> which is in XSLT variable?
>
> Any solution for this problem in XSLT?[/color]

This is not possible in XSLT1.0 (I don't know about 2.0), but you can work around it.

1) Use an extension function that evaluates a string as Xpath
e.g. 'dyn:evaluate' (http://www.exslt.org/dyn/functions/evaluate/index.html)
2) Use a two step tranformation

If you choose the second option, I could help - I have no experience whatsoever with the first option.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Spread the wiki (http://www.wikipedia.org)
Jul 20 '05 #2

Martin Honnen
P: n/a
Martin Honnen


Son KwonNam wrote:

[color=blue]
> Any solution for this problem in XSLT?
> I use JDOM/Xalan for transforming.[/color]

Xalan should support
<http://www.exslt.org/dyn/functions/evaluate/index.html>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #3

Son KwonNam
P: n/a
Son KwonNam
Thank you.

It works perfectly.

I attach the dyn:evaluate example XSL for someone who has the same
problem as mine. With xalan, no need to do anything to use dyn:evaluate.
Just use.

----------------------------------------------------------------------
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:dyn="http://exslt.org/dynamic"
extension-element-prefixes="dyn"[color=blue]
>[/color]
<xsl:output method="xml"/>

<xsl:template match="/">
<ROOT>
<xsl:apply-templates />
</ROOT>
</xsl:template>

<xsl:template match="xpath">
<RESULT>
<XPATH><xsl:value-of select="."/></XPATH>
<xsl:variable name="xpathstr"
select="concat('document(&quot;data.xml&quot;)',.) "/>
<VALUE><xsl:value-of select="dyn:evaluate($xpathstr)"/></VALUE>
</RESULT>
</xsl:template>

</xsl:stylesheet>


Son KwonNam wrote:[color=blue]
> In XSLT, is this possible to get value from xml using XPath
> which is in XSLT variable?
>
> I mean XPath strings can be dynamic while XSL Transforming.
>
> If possible, How??
>
> Because I'm not a native English speaker, it's quite hard
> to make the problem clear. Please see the following example.
>
> There are two XML files.
> One has data, and the other has xpath. I will transform
> the XPath XML.
>
> for example,
>
> * XPath XML
> <xpaths>
> <xpath>/students/student/name</xpath>
> <xpath>/students/student/id</xpath>
> </xpaths>
>
> * Data XML : data.xml
> <students>
> <student>
> <name>John Doe</name>
> <id>234234</id>
> </student>
> </students>
>
> * XSL snippet.
> <xsl:template match="//xpath">
> <xsl:variable name="xpathstring" select="."/>
> <B>XPaht : <xsl:value-of select="$xpathstring"/></B>
> <B>Value : <xsl:value-of select="document('data.xml')/$xpathstring" />
> </B> </xsl:template>
>
>
> As you know, that <xsl:value-of select(document(bla...)/> line
> does not
> work.
>
> Any solution for this problem in XSLT?
> I use JDOM/Xalan for transforming.
>
> Thanks,[/color]
Jul 20 '05 #4

Joris Gillis
P: n/a
Joris Gillis
> With xalan, no need to do anything to use dyn:evaluate. Just use.
Really? Thanks for pointing that out.
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
"Quot capita, tot sententiae" - Terentius , Phormio 454
Jul 20 '05 #5

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework dyn:evaluate