Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] For-each and keys()

From: Steve <subsume@--------->
To:
Date: 8/2/2006 3:18:00 PM
On 8/2/06, David Carlisle <davidc@xxxxxxxxx> wrote:
> XSL goes something like:


>> <xsl:for-each select="$Definitions">
>>   <xsl:value-of select="count(key('oldID',$current))" />
>> </xsl:for-each>
>I really don't understand this.

key() returns all the nodes that match the key _in the current document_
so if you want to look up keys in a different document then (in xslt1)
you need touse  xsl:for-each  to make that document current.
In XSLT2 you could equivalently go
<xsl:value-of select="$Definitions/count(key('oldID',$current))
or
<xsl:value-of select="count(key('oldID',$current,$Definitions))

Ahh, if only. The for-each you mention is what I am attempting,
however, I've gotten no better idea than that (The How gets me, not
the What).

> I really don't understand this.  I should mention there are many other
> branches within $Definitions besides /disabilities.
If $Definitions is defined using document() then it will represent a
well formed document so there can be at most one top level element
(presumably <disabilities>) so I do not see what you can mean by "other
branches"

Disabilities is not the top-level of that document. That is what I meant.



Given that, does that help you understand why the output is not meaningful?



You seem to know, given the way you mention for-each. Perhaps then you
can tell me where the code I have errs.

Here's what I've got. (as short as I can possibly make it).



<xsl:key name="options" match="option" use="@type" />
<xsl:key name="oldID" match="option" use="@oldID" />
<xsl:template match="Record" mode="x">
	<xsl:param name="type" />
	<tr>
		<td>
			<xsl:value-of select="$type" />
		</td>
		<td>
			<xsl:variable name="current" select="disabPrimary" />
			<xsl:for-each select="$cilDefinitions">
				<xsl:value-of select="count(key('oldID',$current))" />
			</xsl:for-each>
		</td>
	</tr>
</xsl:template>
<xsl:template match="/" >
			<table>
				<xsl:for-each
select="$Definitions/disabilities/option[generate-id(.)=generate-id(key('options',@type)[1])]">
					<xsl:sort select="@type"/>
					<xsl:apply-templates mode="x" select="$vP2/Records/Record">
						<xsl:with-param name="type" select="@type" />
					</xsl:apply-templates>
				</xsl:for-each>
			</table>
</xsl:template>


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent