This site has been taken over by the staff of www.ASPDeveloper.Net

Please report errors to suggest@aspdeveloper.net

BizTalk Utilities CV ,   Jobs ,   Code library  
 
 
Page 8 of 28

 

Previous Page Table Of Contents Next Page

XSLT Tutorial

XPath: Functions

XSLT stylesheets can take advantage of large list of functions. The following functions are just a few examples that can be used in XPath queries.

The first part of the XML document that we are going to using in our examples is shown below. A link to the full text of this document is in Worksheet 2 (next page).

<books>
  <book>
    <name link="http://www.amazon.com/exec/obidos/ASIN/0789722429/vbxml">XML by Example</name>
    <author>Benoit Marchal</author>
    <listprice>24.99</listprice>
    <price>17.49</price>
    <review>4.5</review>
    <publish>QUE</publish>
  </book>
  <book>
    <name link="http://www.amazon.com/exec/obidos/ASIN/1861003110/vbxml">Professional XML</name>
    <author>Mark Birbeck, Michael Kay, stev Livingstone</author>
    <listprice>49.99</listprice>
    <price>34.99</price>
    <review>4</review>
    <publish>Wrox</publish>
  </book>
 ...
</books>
          

count

The count function takes a node-set, which returns a number of the nodes present in that node-set

count(nodes)

In the following example we are looking for the number of books with a review of 3.5 and 4:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <p>Review of 3.5 = <xsl:value-of select="count(books/book[review=3.5])"/></p>
        <p>Review of 4 = <xsl:value-of select="count(books/book[review=4])"/></p>
    </xsl:template>
</xsl:stylesheet>

The output:

Review of 3.5 = 1

Review of 4 = 2

NOTE: If you are running the msxml3 parser (October release) and have not run the xmlinst.exe to instruct the parser to run in replace mode, this count example will not run.  For more information on the msxml parser see MSXML Parsers .

To run this example yourself,

Open Worksheet 2 - Simple XPath example

Page 8 of 28

 

Previous Page Table Of Contents Next Page
 

Recent Jobs

Software Specialist, Linux - Finlan
Linux Core Technical Project Manage
Graphics designer at Tanzania. Expe
Integration Specialist Needed - Wor
Virtualization Server Infrastructur

View all Jobs (Add yours)
View all CV (Add yours)






    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP