View Single Post
Old 06-24-2002, 02:17 AM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
Say you want to check the length of the @id node of the context node:

string-length(string(@id))

Will return that number, so you can attach that as a predicate with a =2 to select only nodes with @id value equal to 2.

A quick example document and XSL document:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>

<docEl>
	<test id="aa">Element with id = "aa"</test>
	<test id="aaa">Element with id = "aaa"</test>
	<test id="ab">Element with id = "ab"</test>
	<test id="ac">Element with id = "ac"</test>
	<test id="abb">Element with id = "abb"</test>
</docEl>
And the XSLT document:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html"/>
	<xsl:template match="/">
		<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
			<head>
				<title>Test</title>
			</head>
			<body>
				All elements with id lengths = 2:
				<xsl:apply-templates select="docEl/test[string-length(string(@id)) = 2]"/>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="test">
		<div>
			<xsl:value-of select="."/>
		</div>
	</xsl:template>
</xsl:stylesheet>
Works beautifully in Mozilla 1.0 and IE6.
__________________
jasonkarldavis.com

Last edited by jkd; 06-24-2002 at 02:26 AM..
jkd is offline   Reply With Quote