Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 25th, 2014, 10:04 AM
Authorized User
Points: 151, Level: 3
Points: 151, Level: 3 Points: 151, Level: 3 Points: 151, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Posts: 31
Thanks: 3
Thanked 0 Times in 0 Posts
Default Count the string length of descendant, ignore children

I've the below XML.

Code:
<list>
 <list.item>
        <label>
            <star.page>94</star.page> (a)</label>
 </list.item>
 <list.item>
            <label>(b)</label>  As the
 </list.item>
</list>
and i was trying to get the maximum string length of label by ignoring child nodes of label, I'm trying to do this using the below.

Code:
	<xsl:template name="orderedlist" match="list">
		<xsl:variable name="strl">
			<xsl:choose>
				<xsl:when test="descendant::list.item/label/node()[self::star.page]">
					<xsl:value-of select="max(descendant::list.item/label/string-length(node()[not(*)]))"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="max(descendant::list.item/label/string-length(text()))"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<div>
			<xsl:value-of select="$strl"/>
		</div>
		<xsl:choose>
			<xsl:when test="$strl > '6'">
				<ol class="eng-orderedlist orderedlist1">
					<xsl:apply-templates/>
				</ol>
			</xsl:when>
			<xsl:otherwise>
				<ol class="eng-orderedlist orderedlist">
					<xsl:apply-templates/>
				</ol>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="orderitem" match="list.item">
		<xsl:apply-templates select="./label/node()[1][self::star.page]" mode="first"/>
		<li class="item">
			<div class="para">
				<xsl:if test="./label">
					<span class="item-num">
						<xsl:value-of select="./label/text()"/>
					</span>
				</xsl:if>
				<xsl:choose>
					<xsl:when test="./text()">
						<xsl:apply-templates select="child::node()[fn:not(self::label)]"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text> </xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</div>
		</li>
	</xsl:template>

but it is giving the below error.

Code:
XSLT 2.0 Debugging Error: Error: file:///C:/Users/u0138039/Desktop/Proview/Law%20Reports/HK/11NOV/P1/XML/XSLT/Reports(RXXX_sma-DXXXHX).xslt:1421: Wrong occurrence to match required sequence type -   Details: -     XPTY0004: The supplied sequence ('3' item(s)) has the wrong occurrence to match the sequence type xs:string ('zero or one')
please let eme know where am i going wrong.

Thanks
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display the Length of the String kulfi BOOK: Beginning Microsoft Visual Basic 2010 15 December 30th, 2010 04:41 PM
How to fix string length Ivanchan Excel VBA 2 July 26th, 2007 08:55 AM
string-length problem alapati.sasi XSLT 3 July 4th, 2007 10:08 AM
Chap 3, "Length of String" richajos BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 1 February 25th, 2006 08:38 PM



All times are GMT -4. The time now is 05:04 PM.


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