Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2010, 11:38 AM
Authorized User
 
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default using position()

Hi ,
As per my requirment i have to check
1.If Taxyear is equal to incrYear of <information> tag then ,i have to print that particular information tag details i.e incrYear and IsTransferred
2.the rowcount must be equal to no. of information tag met the above condition



My input xml:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Response xmlns="test.com">
<Result>
<TaxYear>2005</TaxYear>
<information>
<incrYear>2005</incrYear>
<IsTransferred>false</IsTransferred>
</information>
<information>
<incrYear>2005</incrYear>
<IsTransferred>false</IsTransferred>
</information>
<information>
<incrYear>0</incrYear>
<IsTransferred>false</IsTransferred>
</information>
<information>
<incrYear>2004</incrYear>
<IsTransferred>false</IsTransferred>
</information>
</Result>
</Response>
</soap:Body>
</soap:Envelope>

XSLT i wrote :
<LMPReturn>
<LMPMessage>Details <Section RowCount="0">Header</Section>
<xsl:variable name="TaxYear">
<xsl:value-of select="o:Response /o:Result /o:TaxYear"></xsl:value-of>
</xsl:variable>
<xsl:for-each select="o:Response /o:Result /o:information">
<xsl:if test="o:incrYear=$TaxYear">
<count><xsl:value-of select="position()"></xsl:value-of></count>
</xsl:if>
</xsl:for-each>
<Section RowCount='count'>Details
<Row>
<xsl:for-each select="o:Response /o:Result /o:information">
<xsl:if test="o:incrYear=$TaxYear">
<information>
<incrYear>
<xsl:value-of select="o:incrYear"/>
</incrYear>
<IsTransferred>
<xsl:value-of select="o:IsTransferred"/>
</IsTransferred>
</information>
</xsl:if>
</xsl:for-each>
</Row>
</Section>
<Section RowCount="0">Footer</Section>
</LMPMessage>
</LMPReturn>


output xml:
<Section RowCount=2>Details
<Row>
<Information>
<invYear>2005</invYear>
<IsTransferred>false></IsTransferred>
</Information>
<Information>
<invYear>2005</invYear>
<IsTransferred>false></IsTransferred>
</Information>
</Row>
</Section>

now my question is
1.two information tags satisfies the above said condition hence RowCount should have value 2 but by using position i am getting as<count>1</count>
<count>2</count>
could any one please help me in getting the correct count and display in RowCount tag.

Thanks,
 
Old April 27th, 2010, 11:47 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Why would the RowCount attribute ever have a value other than "0" in your XSLT, as that is what you have hard coded it to be.

The following might do the trick, depending on context and various other things that aren't quite clear from the examples you've given).

Code:
<Section RowCount="{count(o:Response/o:Result/o:information[o:incrYear=$TaxYear])}">
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old April 27th, 2010, 12:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Something like this:

Code:
<xsl:variable name="selectedRows" select="information[incrYear = current()/TaxYear]"/>

<xsl:copy-of select="$selectedRows"/>
<RowCount><xsl:value-of select="count($selectedRows)"/></RowCount>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
POSITION() pallone XSLT 8 June 3rd, 2009 10:04 AM
Position barski XSLT 5 July 11th, 2007 01:54 PM
Position: relative; czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 April 7th, 2005 11:22 AM
position:absolute nerssi CSS Cascading Style Sheets 3 February 21st, 2005 10:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.