hello,
I'm a bit new to XSL and I'm trying to do the following: I have an XML file with a number of profiles in it (profile.xml). I wrote a profile.xsl to transform these files into a nice readable format. Now the user would like to filter these xml files based upon a profile of their choice on the client. I have modified my profile.xsl file to include this filter by hand and it works perfectly. The problem is that I need to read this "filter" from an external file (because it can change) and this is where I have tried to use the document function. Here are some examples of my files:
Profile.xml (shortened): - <Main>
-
<profile id="Profile_1">
-
<title>title1</title>
-
</profile>
-
<profile id="Profile_2">
-
<title>title2</title>
-
</profile>
-
<profile id="Profile_3">
-
<title>title3</title>
-
</profile>
-
</Main>
etc...
here is my Profile.xsl (shortened): - <!--This works....-->
-
<xsl:for-each select="Main/profile[@id=Profile_1']">
-
<!--This one does not-->
-
<!--<xsl:for-each select="document(testing.xml')/ProfileSelection/SelectedProfile)">-->
-
<td >
-
<xsl:value-of select="@id"/>
-
<xsl:value-of select="title"/>
-
<xsl:apply-templates select="select">
-
</xsl:apply-templates>
-
</xsl:for-each>
here is my testing.xml file: - <?xml version="1.0" encoding="utf-8"?>
-
<ProfileSelection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml">
-
<SelectedProfile>Benchmark/profile[@id=Profile_1']</SelectedProfile>
-
</ProfileSelection>
-
This item in my xsl is my problem (I believe): - <!--<xsl:for-each select="document(testing.xml')/ProfileSelection/SelectedProfile)">-->
the document function does not return a node set in this case, which is what the for-each is looking for. I've tried to use the node-set() function from xmlns:exsl="http://exslt.org/common"> but this has not worked. I am able to verify that the document() is reading the correct string value from the testing.xml file, but for-each just will not use it.
Does anyone know what I am doing wrong?
Thanks in advance,
Pete
15 7350
You're treating a string
"Benchmark/profile[@id=Profile_1']"
as an xpath to be executed. The processor only recognizes it as a string.
You need to use the exslt function, dyn:execute() EXSLT - dyn:evaluate
eg: <xsl:for-each select="dyn:evaluate(document(testing.xml')/ProfileSelection/SelectedProfile))">
Unfortunately, this is not implemented on most processors.
you have some syntax violation in your document() call. try this: - <xsl:for-each select="document('testing.xml')/ProfileSelection/SelectedProfile">
-
<!-- code coming here -->
-
</xsl:for-each>
and like jkmyoung said, strings won't work for XPath expressions.
regards
Unfortunately I don't have a processor that can handle, natively, the exslt functions and the dyn.xsl file does not seem to exist.
if it's just the profile id that needs customizing, why not storing the value of the id and using that in a comparison. - <?xml version="1.0" encoding="iso-8859-1" ?>
-
<profile_id>Profile_1</profile_id>
- // ...
-
<xsl:variable name="profile" select="document('testing.xml')/profile_id/text()"/>
-
// ...
-
<xsl:value-of select="//profile[@id = $profile]"/>
I don't know if there's a better solution, but it should work.
I could do that, only issue is that I have 27 profiles and the xsl code will get very messy.
that depends on what exactly you want to do with that user provided profile name. currently I have no idea what you need them exactly for (ok, I have a dim idea).
Ok, let me try ;-) to explain a little better. When the xml file is created it has all 27 profiles in it. When the user goes to look at these "profile" xml files the xsl puts it into a nice readable format, BUT it shows all the profiles. Some users only want to see, say profile 1 or 2, but they may need at some point to look at another profile. This is why I want them to have all the profiles, but be able to filter on only the profiles they need (so they can print them off and go out into the field with the info).
My idea was to add a combo box to the xsl so they could pick from a drop down what profiles they were interested in. When they did that an onChange event reloaded the page (java script), and wrote out to the testing.xml file what profile they were interested in. then when it reloaded it would show only that profile via the document() function. sounds pretty slick huh? too bad it doesn't work :-(
don't give up yet, I still got some ideas left.
user xml, say 2 profiles to show - <?xml version="1.0" encoding="iso-8859-1" ?>
-
<profile>
-
<profile_id>Profile_1</profile_id>
-
<profile_id>Profile_3</profile_id>
-
</profiles>
xsl, (rough sketch) - <xsl:for-each select="document('user.xml')/profile_id">
-
<xsl:value-of select="$node[@id = current()/@id]/title"/>
-
//...
idea: loop over the elements in the user file, that should give you the desired number. the $node variable refers to a <profile> node of the original xml (use <xsl:variable> to define it). current() gets you the node of the for-each loop.
another possibility includes a template using <xsl:with-param> basing on the same principle.
I'll have to play around with that a little bit and try to attack it from that way. thanks Dormilich, I appreciate the help.
nevermind, we're here to help.
Is it possible for you to generate the XSLT dynamically? Eg when they select a profile, it takes the information from the filter, to create a custom XSLT. Then it runs the base XML through the new XSLT.
jkmyoung, thats what I'm trying to do. As they select a profile from the combo box contained in the xslt, it re-applys the xml to the slightly modified xslt (with a different filter thist time) showing them only their profile.
What is your encapsulating code for writing the Profile.xsl each time?
Just want to clarify: I mean an entirely new xslt file. No use of document(); no use of of <xsl:param>.
I was using a javascript to write out to the text file. and was only going to do a window.location.reload(); to reload the xsl and the xml, I'm not sure if that will work.
Currently I'm trying Dormilich's idea of using the choose function, but I'm having trouble with that as well. I set a default param at top to be 'all profiles'.
I then draw the combo box with the fixed list of profiles (in xslt code), and an onChange event. So on default the 'all profiles' are loaded. when the user clicks the combo box, on change switches the param to be "profile 1" and fires the reload event. The XSL file has a choose method in it to test the value of my param, i.e. <xsl:when test="*[name() = $selectedProfile] = 'profile1'">. which is not working. I'm not sure how I can test the results from my combo box via the xsl and then reload it accordingly.
Reread entire thread. -
<xsl:param name="profileId"/>
-
....
-
<xsl:for-each select="Main/profile[@id=$profileId]">
-
What javascript xslt processor are you using? (eg. post code). Might be something like: -
xslproc = xslt.createProcessor();
-
xslproc.input = xmldoc;
-
xslproc.addParameter("profileId", comboBoxValue);
-
Depends on the XSLT processor you're using.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dSchwartz |
last post by:
What I think I'm looking for is a way (in XSL stylesheet) to get the
contents of a directory. How can this be accomplished?
more detailed:
/root
index.aspx
xsl_style.xsl
/xml...
|
by: Razzbar |
last post by:
I need to be able to conditionally load a remote script, using
the "<script src=..." syntax. Or some other way. I've seen
people writing about using the document.write method, but it's
not working...
|
by: Stumped and Confused |
last post by:
Hello,
I really, really, need some help here - I've spent hours trying to find a
solution.
In a nutshell, I'm trying to have a user input a value in form's
textfield. The value should then be...
|
by: scripter199 |
last post by:
Hi,
Im adding textboxes dynamically from an onclick event that calls the function below:
function addRowDynamic()
{
rowCnt++;
lookupCnt++;
id++;
//add a row to the rows...
|
by: lintolawrance |
last post by:
how we can get the record count of a datalist using document.getElementByID()
|
by: anupamaavadutha |
last post by:
hi all,
iam new to javascript. i have problem calling javascript functions.iam designing a calender page.here is my code.
<%@ page...
|
by: Randall |
last post by:
I am a newbie trying to learn the DOM. Can someone tell me why the
first alert statement returns null, and the second returns the value
33px (which was set using the style="top:33px;" in the DIV...
|
by: =?Utf-8?B?RGF2aWRHQg==?= |
last post by:
OK, so I've created and loaded an XMLDocument object.
But how do I go about using it? Specifically, how do I:
1) move to the first node (I assume I start on it when I load the XML?)
2) move to...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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,...
| |