XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
clare EmmaSubject: Using variables
Author: clare Emma
Date: 02 Aug 2005 11:40 AM
Hi,

I'm trying to write a stylesheet that will analyse some boolean values in my XML document and increment or decrement a value. I've declared a variable within the stylesheet to hold this but I'm not sure how to change this value or if this is the best way to do it, any help would be most appreciated.

Clare

Postnext
Ivan PedruzziSubject: Using variables
Author: Ivan Pedruzzi
Date: 02 Aug 2005 12:47 PM
In XSLT variables are immutable.
In your case I would use the count function.

Here an example

XML
<?xml version="1.0"?>
<books>
<book>
<title>AAA</title>
<paperback>false</paperback>
</book>
<book>
<title>BBB</title>
<paperback>true</paperback>
</book>
<book>
<title>CCC</title>
<paperback>true</paperback>
</book>
</books>


The following XSLT prints the number of paperbacks

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:value-of select="concat('Paperback ', count(/books/book[paperback='true']))"/>
</xsl:template>

</xsl:stylesheet>


Hope this helps
Ivan Pedruzzi
Stylus Studio Team

Postnext
clare EmmaSubject: Using variables
Author: clare Emma
Date: 03 Aug 2005 04:03 AM
Oh thanks, that's useful to know (I'm real new it this). But what if I had a couple more boolean values within <book> and wanted to count. Is there any easy way of doing that?

I had something like:

<book>
<title>AAA</title>
<paperback>false</paperback>
<english>true</english>
<inPrint>true</inPrint>
</book>

and for each book I will create a value based on the three booleans within it, say true will add one to my value and false will subtract one. Ultimately I want to add this calculated value to a new XML document using the stylesheet.

Thnaks,
Clare

Postnext
Ivan PedruzziSubject: Using variables
Author: Ivan Pedruzzi
Date: 03 Aug 2005 12:04 PM

Try the attached solution it should be auto explanatory.

Hope this helps
Ivan Pedruzzi
Stylus Studio Team


Documentpaperback.xsl


Unknownpaperback.xml

Posttop
clare EmmaSubject: Using variables
Author: clare Emma
Date: 04 Aug 2005 10:49 AM
Thanks Ivan,

You've been really helpful!!

Clare

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.