473,387 Members | 1,573 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,387 software developers and data experts.

Selcting filtered node set based on variable

Question for the masses...

Lets say I have variable with the following contents
"aaaa bbbb ccccc dddd". The format is not specific and the space
delimiter could be changed to any other.

How would i count and/or select the nodes where a child nodes value is
not contained in this list. Or the reverse scenario would be sufficent
whereas I count the nodes whose child nodes value is contained.

A contrived example of my situation follows...thanks for the help.

<root>
<limbs>
<branch>
<name>a</name>
<flower>big</flower>
</branch>
<branch>
<name>b</name>
<flower>big</flower>
</branch>
<branch>
<name>c</name>
<flower>large</flower>
</branch>
<branch>
<name>d</name>
<flower>giant</flower>
</branch>
</limbs>
<root>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:variable name="Exclude">
<xsl:value-of select="big large"/>
</xsl:variable>
<xsl:template match="/">
<xsl:variable name="DomainCount">
<xsl:value-of select="count(//branch[contains($Exclude,
flower)])"/>
</xsl:variable>
</xsl:template>
</xsl:stylesheet>

Jul 20 '05 #1
2 1522
> Question for the masses...
Panem et circenses Lets say I have variable with the following contents
"aaaa bbbb ccccc dddd". The format is not specific and the space
delimiter could be changed to any other.

How would i count and/or select the nodes where a child nodes value is
not contained in this list. Or the reverse scenario would be sufficent
whereas I count the nodes whose child nodes value is contained.

A contrived example of my situation follows...thanks for the help.

<root>
<limbs>
<branch>
<name>a</name>
<flower>big</flower>
</branch>
<branch>
<name>b</name>
<flower>big</flower>
</branch>
<branch>
<name>c</name>
<flower>large</flower>
</branch>
<branch>
<name>d</name>
<flower>giant</flower>
</branch>
</limbs>
</root>


Hi,

In this situation, the following stylesheet might work:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:variable name="Exclude">
big large
</xsl:variable>

<xsl:template match="/">
<xsl:variable name="DomainCount">
<xsl:value-of select="count(//branch[not(contains($Exclude,flower))])"/>
</xsl:variable>
</xsl:template>

</xsl:stylesheet>

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #2
<xsl:variable name="Exclude">
<xsl:value-of select="big large"/>
</xsl:variable>

note it's simpler and a lot more efficient to do

<xsl:variable name="Exclude" select="' big large '"/>

(and you'd omitted the quotes around the string 'big large'.)
I added a space at either end as well (used below)

<xsl:variable name="DomainCount">
<xsl:value-of select="count(//branch[contains($Exclude,
flower)])"/>
</xsl:variable>

again that would be better as

<xsl:variable name="DomainCount" select="count(//branch[contains($Exclude,
flower)])"/>
which works but to avoid the possibility of one name being a substring
of the other, you can append a space to either side:
<xsl:variable name="DomainCount" select="count(//branch[contains($Exclude,
concat(' ',flower, ' '))])"/>

so:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:variable name="Exclude" select="' big large '"/>

<xsl:template match="/">

<xsl:variable name="DomainCount" select="count(//branch[contains($Exclude,
concat(' ',flower, ' '))])"/>
[<xsl:value-of select="$DomainCount"/>]
</xsl:template>
</xsl:stylesheet>
<root>
<limbs>
<branch>
<name>a</name>
<flower>big</flower>
</branch>
<branch>
<name>b</name>
<flower>big</flower>
</branch>
<branch>
<name>c</name>
<flower>large</flower>
</branch>
<branch>
<name>d</name>
<flower>giant</flower>
</branch>
</limbs>
</root>
$ saxon flower.xml flower.xsl

[3]

3 nodes have flower= big or large
Jul 20 '05 #3

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

Similar topics

3
by: Blaise Garant | last post by:
Hi I've made a stylesheet to transform my data into XSL-FO. This stylesheet used to work with MSXSL 4.0 but I've got some issues in ..NET. First, I changed removed all the "node-set()" function...
6
by: GSteven | last post by:
(as formerly posted to microsoft.public.access.forms with no result) I've created a continuous form which is based on a straightforward table (ex - customers - 100 records). On the form there is...
7
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
1
by: Ken | last post by:
I have a form that has a command button on it to open a report. The report is based on the forms data, if it's filtered the report is filtered, if the form is showing 100 records the report is...
3
by: melnhed | last post by:
---Report the current filtered records from a Form--- Hello All, I've seen this topic discussed before, but the solution described then doesn't work in my particular case. My Config: ...
2
by: Stephen | last post by:
Hi Using: Visual Web Developer Express 2005 Could someone explain to me what the "node" does in a path - such as; <siteMapNode title="Hardware" url="Default.aspx?node=hardware"> Has it...
0
by: HP17 | last post by:
Hi all, I am a bit desperate already trying to display a XML file using XSLT. I create a table and use <xsl:for-each> to extract every element node. This is working fine. What I want now is so...
7
by: Dag Sunde | last post by:
I want to use the format-number function to output a number with a specific number of decimals, based on the content of a node... Is there any smart way to generate differnet strings based on a...
6
by: Nettle | last post by:
Purpose: I am creating a mailing distribution list database. Users should be able to filter/search contacts and add them to distribution lists they have created. My problem? I can't add multiple,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
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?
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
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
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,...

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.