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 November 25th, 2014, 10:04 AM
Authorized User
 
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





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





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