473,416 Members | 1,859 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,416 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 21175
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 output will be 312.5. How can I do with the .Net?? ...
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 in the compile command but assembly will not...
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 ultimate goal would be to have a statement similar...
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, Response.Output, Nothing) Which takes my xml file...
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 can use to evaluate this string and get an logical...
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 that looks like this "True AND True AND True" and...
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 first page and i have a function that retreives...
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"/> xsl;variable name="test2"...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.