473,407 Members | 2,546 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,407 software developers and data experts.

XSL Filter Help Needed

I have an XML document which looks like
<folder>
<link author="ME"/ url="something">
<link author="YOU" url="something else"/>
<folder>
<link author="ME"/ url="something">
<folder>
<link author="ME"/ url="something">
<link author="YOU" url="something else"/>
</folder>
</folder>
</folder>

There can be any number of depths of folders and there can be any
number of authors.

What I want to do is parse the XML and return another XML document with
the applicable links and structure

My XSL looks like
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:param name="Filter" select="'default value'"/>
<xsl:template match="node() | @* | / | root">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match='treenode[@Author=$Filter]' />
</xsl:stylesheet>

The idea is generally to be able to return to entire hierachical
structure for each link who have a matching author

The problem is I get an error from the treenode[@... line saying
invalid key pattern. It either has a variable reference or key
function.

Any ideas how I can fix this?

Sep 2 '06 #1
4 1330


ri************@hotmail.com wrote:
I have an XML document which looks like
<folder>
<link author="ME"/ url="something">
^^^
<link author="YOU" url="something else"/>
<folder>
<link author="ME"/ url="something">
^^^
<folder>
<link author="ME"/ url="something">
^^^

What are those slash characters supposed to do there? That is not XML.

<xsl:template match='treenode[@Author=$Filter]' />
You have elements named 'folder', 'link' in the above sample but not a
single element named 'treenode'. And the attribute is named 'author' and
not 'Author'. So I have no clue what that stylesheet template has to do
with the markup presented above.

The problem is I get an error from the treenode[@... line saying
invalid key pattern. It either has a variable reference or key
function.
That error does not sound as if it comes from the stuff you have shown.
Do you have any xsl:key elements in the stylesheet?

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 3 '06 #2
Sorry, there were some typos in my original post. I'd generally
offered an example not the actual xml. I have amended the example
based on the comments.

This is all of done thus far, the XSL is as I currently have it. The
Transforming code does little more than apply an argument and apply the
XSL to the XML
<Folders>
<folder>
<link author="ME" url="something"/>
<link author="YOU" url="something else"/>
<folder>
<link author="ME" url="something"/>
<folder>
<link author="ME" url="something"/>
<link author="YOU" url="something else"/>
</folder>
</folder>
</folder>
</Folders

My XSL looks like
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
<xsl:param name="Filter" select="'default value'"/>
<xsl:template match="node() | @* | / | root">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match='link[@author=$Filter]' />
</xsl:stylesheet>>
The problem is I get an error from the treenode[@... line saying
That error does not sound as if it comes from the stuff you have shown.
Do you have any xsl:key elements in the stylesheet?
Not that I'm aware of as I said wht tyou see is what I've got

I've seen variables used many times in apply-templates select=.....
statements but not in match statements. Does the match support
variables?
Thanks for your response

Sep 3 '06 #3


ri************@hotmail.com wrote:

I've seen variables used many times in apply-templates select=.....
statements but not in match statements. Does the match support
variables?
No, it does not. A match attribute takes a pattern and the specification
restricts that with "It is an error for the value of the match attribute
to contain a VariableReference".

So you will need to write a template for link elements and then do your
checks in the template e.g.
<xsl:template match="link">
<xsl:if test="@author != $Filter">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 3 '06 #4
<xsl:template match="link">
<xsl:if test="@author != $Filter">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>
Unfortunately it didn't work. I believe the issue is that the folder
element doesn't have an author attribute so doesn't get processed.

If I test the element name and ascertain it's a folder or not the
correct Author, then carry on processing it could build a hierachy with
no links in any of the folders(I think)

The problem is I wish to use to build a navigation tree. The users
will only want to see links or folders containing links applicable to
them. Drilling down through several levels and having no links at the
end would definately be an issue for them

Is this possible or should I try to find a different way

Thanks for your response

Sep 3 '06 #5

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

Similar topics

1
by: jeffgeorge | last post by:
Hi all. Trying to move Filter By Selection, Filter By Form, and Apply/Remove Filter directly into my form. No luck. Is there anyway to move them into the header of the form or, as another...
2
by: Patrick Gonzalez | last post by:
Is it possible to use the built-in filter functions (ie. "Filter by Selection", etc..) when a form's recordsource has been set to a recordset object during the load event. When I try to do this, I...
1
by: lorirobn | last post by:
Hi, I have a report that works just fine. Now I would like to add the capability to choose selection criteria to limit what is displayed. I created several reports that do this, but they used...
8
by: fonzie | last post by:
I have an edit button on my form that changes the recordsettype of the form, causing the form to requery. If I have a filter applied on the form before I hit the edit button, it is not applied to...
2
aestheticmind
by: aestheticmind | last post by:
Hello, How do you evaluate multiple values in a single Variable? Can someone give me a hand on how to set $filter so that it will evaluate all of the values. Right now it will only eval the first...
2
by: Henrootje | last post by:
Hello there! I have a piece of code in a module (function) that constructs a filter. But now I run into a problem..... It seems that I can only set a filter form a module if I open the form...
3
by: birt | last post by:
I know I am getting in my own way .... so someone please save me from myself! I created a form and rather than force the users to scroll through all the records to find theirs I decided to have...
8
by: Abedin | last post by:
I have 9 digits in form of "111020402". Then I have another 9 digits in form of "111020403". I have 100,000 records of these two 9-digit numbers. I want to filter this as follows: District:...
1
by: Joelle | last post by:
Hi everyone, i am really stack!i need help I have this report:"RequirementObjects_Report",i have also a multiselect listbox whicg contains a list of products.what i want to do is to filter the...
3
by: franc sutherland | last post by:
Hello, I have a report which I filter using the me.filter command in the OnOpen event. Me.Filter = "OrderID=" & Forms!variable_form_name! Me.FilterOn = True I want to be able to open that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
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
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.