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 21st, 2010, 08:54 AM
Authorized User
 
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default How to populate a variable dynamically

Hi,
My requirement is ,
i have to print the count of multiple occurances of any tag.
by using count function i found the the occurances. i am failing at pass the value.
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="http://test.com">
<Result>
<Users>
<Summary>
<ID>186886</ID>
<Status>N</Status>
</Summary>
<Summary>
<ID>186888</ID>
<Status>N</Status>
</Summary>
</Users>
</Result>
</Response>
</soap:Body>
</soap:Envelope>

summary tag is occuring twice so RowCount =2

xslt :
XSLT :<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:o="http://test.com.websevices">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no" />
<xsl:template match="/soap:Envelope">
<xsl:apply-templates select="soap:Body"/>
</xsl:template>
<xsl:template match="soap:Body">
<LMPResponse>
<Message>Details
<RowCount><xsl:value-of select="count(o:Response /o:Result /o:Users /o:Summary)"/>
</RowCount>
<Section RowCount="populate the value from RowCount">Details
<xsl:for-each select="o:Response /o:Result /o:Users /o:Summary">
<Row>
<ID>
<xsl:value-of select="o:Response /o:Result /o:Users /o:Summary /o:ID"/>
</ID>
<Status>
<xsl:value-of select="o:Response /o:Result /o:Users /o:Summary/o:Status"/>
</Status>
</Row>
</xsl:for-each>
</Section>
<Section RowCount="0">Footer</Section>
</Message>
</LMPResponse>
</xsl:template>
</xsl:stylesheet>

now i am not able to populate the count found in RowCount using
<RowCount><xsl:value-of select="count(o:Response /o:Result /o:Users /o:Summary)"/>
</RowCount> to <Section RowCount="populate the value from RowCount">

Can any one help in this.
Thanks,
Divya
 
Old April 21st, 2010, 09:21 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You need an attribute value template:

Code:
<Section RowCount="{expr}">
where expr is any XPath expression.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 21st, 2010, 09:44 AM
Authorized User
 
Join Date: Apr 2010
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks Micheal.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically populate a label MaxGay2 VB.NET 2002/2003 Basics 27 November 15th, 2006 04:17 PM
Populate a Variable From Access Table sirmilt Access 5 March 21st, 2006 01:34 AM
create a variable dynamically in JavaScript crmpicco Javascript How-To 2 October 4th, 2005 06:14 AM
Dynamically populate crystal report from .NET DTCT Crystal Reports 0 November 12th, 2004 11:46 AM





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