p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

xslt thread: how to uniquely identify elements in XSLT for parameter passing?

Message #1 by "Edward Tanguay" <edward80133@h...> on Wed, 26 Jun 2002 07:38:48 +0000
I think I would solve this by running a transformation that creates a
version of your flashcards file with id attributes added. You can then
use this augmented file as the base file for the interactive

To add the ids, you can do:

<xsl:template match="/">

<xsl:template match="flashcard">
<flashcard id="{generate-id()}">
<xsl:copy-of select="@*"/>

You can't use generate-id directly in the interactive application
because (a) there is no way of finding a node given its generated id,
and (b) the results of generate-id are not guaranteed to be stable from
one transformation to the next.

Michael Kay
Software AG
home: Michael.H.Kay@n...
work: Michael.Kay@s... 

> -----Original Message-----
> From: Edward Tanguay [mailto:edward80133@h...] 
> Sent: 26 June 2002 08:39
> To: P2P_XSLT
> Subject: [xslt] how to uniquely identify elements in XSLT for 
> parameter passing?
> 1. I have an XML file with hundreds of flashcards in it:
> <flashcards>
>   <flashcard question="What is XML?" answer="XML is..."/>
>   ...
> </flashcards>
> 2. I want to create an XSLT file which lists out the 
> questions as hyperlinks 
> and when the user clicks on the hyperlink, a new window opens 
> with the 
> answer.
> 3. The problem is, how do I IDENTIFY each record so that I 
> can pass this id 
> as a parameter into the next window which then looks up that 
> element? If I 
> were using a database I would have the "id" field which is 
> auto-increment, I 
> can pass the id as a parameter no problem. But my flashcard 
> elements do not 
> have an ID attribute that uniquely identifies them.
> a. Can I use position() somehow?
> b. Is there some kind of auto-increment function in XSLT that 
> I can use? Do 
> I need to
> c. Do I need to run an XSLT transformation which adds ID 
> fields to my tags 
> based on position() perhaps?
> I'm sure this is a common problem for those who are using XML 
> files as 
> databases and need to implement this primary key function to 
> identify their 
> records/elements.
> How does one solve this problem in XSLT?
> Thanks,
> Edward Tanguay
> http://www.tanguay.info
> _________________________________________________________________
> Get your FREE download of MSN Explorer at 
> http://explorer.msn.com/intl.asp.
> ---
> Change your mail 
> options at 

  Return to Index