[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: What does position() really return
Subject: Re: What does position() really return
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Mar 2001 17:56:48 +0000
|
Jan,
You are getting bitten by whitespace-only text nodes in your source, that
may be invisible to your eye, but that are there (and getting counted)
nonetheless:
<Personen>^
^^^^^<Person>Jan</Person>^
^^^^^<Person>Peter</Person>^
^^^^^<Person>George</Person>^
^^^^^<Person>Danny</Person>^
</Personen>
So when apply-templates is fired in the Personen template, the nodes to be
processed are
1. A text node (contains whitespace)
2. <Person>Jan</Person>
3. A text node (contains whitespace)
4. <Person>Peter</Person>
etc.
Put a top-level element such as
<xsl:strip-space elements="Personen"/>
and these will be stripped.
But the rule is, unless otherwise instructed, an XML parser passes all
whitespace to the application.
These nodes are throwing off the count of your position. Sometimes they
don't matter. Here, they do.
Hope that helps,
Wendell
At 10:19 PM 3/15/01, you wrote:
Hi,
I'm trying to find out, what the position() function really returns.
Browsing through the archive, some books and what's on the Internet
and experimenting with it only increases my confusion. I have the
following XML/XSL-code:
<?xml version="1.0" encoding="iso-8859-1"?>
<Personen>
<Person>Jan</Person>
<Person>Peter</Person>
<Person>George</Person>
<Person>Danny</Person>
</Personen>
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="iso-8859-1" method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>Testfile</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Personen">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="Person">
<p>Output: <xsl:value-of select="position()"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="."/>
</p>
</xsl:template>
</xsl:stylesheet>
Running this with Saxon (Instant-Saxon, version 6.2.1 under Win98)
produces the following result (result 1):
Output: 2, Jan
Output: 4, Peter
Output: 6, George
Output: 8, Danny
Changing the "Personen" template to:
<xsl:template match="Personen">
<xsl:apply-templates>
<xsl:sort select="."/>
</xsl:apply-templates>
</xsl:template>
generates (result 2):
Output: 6, Danny
Output: 7, George
Output: 8, Jan
Output: 9, Peter
and once more changing "Personen" to:
<xsl:template match="Personen">
<xsl:apply-templates select="Person">
<xsl:sort select="."/>
</xsl:apply-templates>
</xsl:template>
results in (result 3):
Output: 1, Danny
Output: 2, George
Output: 3, Jan
Output: 4, Peter
My confusion comes from the following:
- I have expected the position numbers *always* in the range between 1 and 4
- Why are the position values in result 1 multiples of 2 ?
- Why are results 2 and 3 different (in terms of the position numbers) ?
Thanks in advance
Jan
___________________________________________________________________
BISS GmbH, Chaukenweg 12, D-26388 Wilhelmshaven, Germany
Phone: +49 4423 9289-0, Fax: +49 4423 9289-99
Dr. Jan Mazac, mailto: jwm@xxxxxxxxxxxx
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
======================================================================
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|