472,342 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Cand XSLT evaluate XPath in String variable?

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
4 21078
Hi,
In XSLT, is this possible to get value from xml using XPath
which is in XSLT variable?

Any solution for this problem in XSLT?


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


Son KwonNam wrote:

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


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

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #3
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"
<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: 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 #4
> 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: MN | last post by:
Hi All, I have a string like ... String str1 = "(15*20)+12.5"; I want to evaluate this string to get the mathematical output. Ideally...
5
by: TJS | last post by:
How can I evaluate this string in vb.net " Dim submenu0 As New skmMenu.MenuItem('Home', '') "
13
by: TJS | last post by:
How can I evaluate this string in vb.net " Dim submenu0 As New skmMenu.MenuItem('Home', '') " I have tried this with skmmenu as a reference...
0
by: KenRoy | last post by:
I want to be able to evaluate a string value as either True or False. So if the string was "0 Or (1 or 0)" the value True would be returned. My...
2
by: darrel | last post by:
I don't do a lot with XML, so I always get a bit lost navigating the XML classes. In the past, I've used this: xslt.Transform(doc, xslArg,...
1
by: mat14 | last post by:
Hi, Is it possible to evaluate a string to get a logical output? For Eg. var string1 = "true && false || true" Is there any method that i...
2
by: yarborg | last post by:
This is kind of a weird one and hard to find answers online because of the format of the question. Essentially I want to be able to have a string...
8
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I have a custom business object of type Person. i created a page with check boxes that will post to a second page that is strongly typed with the...
0
by: prao2005 | last post by:
how to check whether the value of a string variable is Yes or No? xsl;variable name="test1" select="DBE:OBJECT/DBE:ATTRIBUTE/DBE:String"/>...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

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.