Subject: question on using generate-id with the KEY function
From: "Mattoo, Utpal" <Utpal.Mattoo@xxxxxxxxxxx>
Date: Thu, 21 Aug 2008 14:31:41 -0500
|
My question is kinda long...thanks for helping my with my question
This question is in reference to the post at
http://sources.redhat.com/ml/xsl-list/2000-07/msg00059.html
Where it says ::
"how to retrieve the unique elements so that you can identify what part
numbers are used in your file:
*[@partNum and generate-id(.)=generate-id(key('parts', @partNum))]
In the code below:
What is the difference between the following 2 lines (Line 1 vs Line 2)
(I know what these lines do, but i dont know HOW. Please find related
XML at the end of the file )----
Line 1
<xsl:apply-templates select="*[@partNum and
generate-id(.)=generate-id(key('parts', @partNum))]" />
Line 2
<xsl:apply-templates select="*[generate-id(.)=generate-id(key('parts',
@partNum))]" />
ALSO what does this line do
-- generate-id(.)=generate-id(key('parts', @partNum)) ---
probably retrieves a part number only once but I don't understand
how...
BUT how is the line different from
-- generate-id(.)=generate-id(key('parts', @partNum)[1]) ---
=======================
The complete XSL is: ( in XSL below -- i should be using either Line 1
or Line 2 above }
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:key name="parts" match="*[@partNum]" use="@partNum" />
<xsl:template match="/PARTS">
<xsl:apply-templates select="*[@partNum and
generate-id(.)=generate-id(key('parts', @partNum))]" />
<xsl:apply-templates
select="*[generate-id(.)=generate-id(key('parts', @partNum))]" />
<!-- <xsl:apply-templates select="*[key('parts', @partNum)]"
/>-->
</xsl:template>
<xsl:template match="*[@partNum]">
<xsl:value-of select="@partNum" />
<xsl:value-of select="count(key('parts', @partNum))" />
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<PARTS>
<CPU partNum="1345" />
<CPU partNum="1345" />
<CPU partNum="1345" />
<CPU partNum="1345" />
<CPU partNum="11111345" />
<CPU partNum="111111111345" />
</PARTS>
|