xsl-list
[Top] [All Lists]

[xsl] question on using generate-id with the KEY function

2008-08-21 12:32:06

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: 

  *[(_at_)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="*[(_at_)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="*[(_at_)partNum]" use="@partNum" />

            

      <xsl:template match="/PARTS">      

           <xsl:apply-templates select="*[(_at_)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="*[(_at_)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>

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>