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

Help with XSLT counting...

I have XML like the following:
Expand|Select|Wrap|Line Numbers
  1. <book>
  2.  <title>
  3.  <author>
  4. <book>
  5. :     :     :
  6.  
and so on for my example.

I need XSLT to produce a listing of books where <author> = "user supplied string". But, if not match occurs, then I want to display "No matches found" instead.

So - in my extremely novice experience, I code something like:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="/">
  2.  <xsl:for-each select="book">
  3.   <xsl:if test="author='usersuppliedstring'">
  4.    <xsl:value-of select="title"> <br />
  5.   </xsl:if>
  6.  </xsl:for-each>
  7. </xsl:template>
  8.  
But, in this simple example, how do I know if I didn't find any matching authors so that I can output the text "No matches found"?

And - what if the <xsl:if ...> test is more complex and nested? I need to see if anything in the middle was selected - or in other words, count how many matches were output and if the count is zero, output "No matches found".

Thanks,
Jeff
Oct 3 '07 #1
1 1378
jkmyoung
2,057 Expert 2GB
Something like:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="/">
  2.  <xsl:for-each select="book">
  3.   <xsl:if test="author='usersuppliedstring'">
  4.    <xsl:value-of select="title"> <br />
  5.   </xsl:if>
  6.  </xsl:for-each>
  7.   <xsl:if test="not(book[author='usersuppliedstring'])">
  8.     <xsl:text>No Results Found</xsl:text>
  9.   </xsl:if>
  10. </xsl:template>
Oct 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Lizard | last post by:
OK, total newbie here, so this may be a mind-numbingly dumb question AND I may be phrasing it badly. I have an xsl:template which looks like this: <xsl:template match="LoanRecord"> <hr>...
3
by: Graham | last post by:
Hi, I am having trouble getting XSL to count the members of a group. What I am trying to do is group by <objectid.Contactid> and count the number of <activityid>'s for each <objectid.contactid>....
2
by: Graham | last post by:
Hi, I am in need of help trying to count the number of records that a Key group contains. I am a newbie and apologise if this seems a dumb request! I have the following XSLT and keep getting...
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
4
by: Herr Herrner | last post by:
hi, i'm trying to count something in xml via xsl and don't quite get it. i have something like (don't mind it's not logical) <doc> <s> <w type="a">how</w> <w type="b">are</w> <w...
22
by: Rafia Tapia | last post by:
Hi all This is what I have in mind and I will appreciate any suggestions. I am trying to create a xml help system for my application. The schema of the xml file will be <helpsystem> <help...
4
by: gualtmacchi | last post by:
I'm processing an XML input file getting a plain text file where from M nodes I got N output lines... It's not relevant but the input file is a recordset coming from a database and the output is...
12
by: Jeff Calico | last post by:
I have 2 XML data files that I want to extract data from simultaneously and transform with XSLT to generate a report. The first file is huge and when XSLT builds the DOM tree in memory, it runs...
2
by: manishj | last post by:
Hello! I m trying to transform a XML file into new XML file . Description: Each unique value from the <name> elements in the input record are to be uniqued, alphabetized and stored with a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.