Re: [xsl] Processing IDREFS attributes

Subject: Re: [xsl] Processing IDREFS attributes
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 01 Nov 2005 22:52:51 -0500
At 2005-11-01 16:08 -0800, Dan Vint wrote:

below

At 02:23 PM 11/1/2005, you wrote:
*If* you have properly declared the id attributes, for my example they are called id=, something along the lines of:

<!ATTLIST foo id ID #IMPLIED>


Yes and I had the references defined as IDREFS #IMPLIED as well.

That turns out to be irrelevant ... only the ID declarations are required. The string or node set that you supply to the id() function can be anything.


then you should be able to say:

  <xsl:for-each select="id(@references)/@id">
    <xsl:if test="position()>1"> </xsl:if>
    <xsl:value-of select="."/>
  </xsl:for-each>

A slight twist on this does what I wanted, which was to go find the element that has the ID:


  <xsl:for-each select="id(@references)/@id">
    <xsl:value-of select="id(.)"/>
  </xsl:for-each>

This produces the content of the element with the assigned ID. Without it, I just got the id value. I'm not sure why you have the position test, can you explain that?

To add a space separator between each of the ID values ... without it your result tree would just get a string of concatenated letters. I thought your intention was to report the unique ID values from the IDREF pointers.


With my original code with added context:
<xsl:templete match='foo'>
<xsl:for-each select="id(@references)">
        <xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>

It didn't loop for one problem, so there was only a single output, instead of two values as I expected. The output was just the same value as my @references content.

I can't fathom what is going on and why the @references is just being repeated ... that code should have given you the concatenated string values of the elements whose ID typed attribute has a value in the tokenized set of values of the @reference node.


In my original code I had this as well, trying to get to the content of the element referenced, but nothing was being output, so I used the current value just to see if anything was being looked up.

<xsl:value-of select="id(.)"/>

That just supplies the value of the current node to the id() function for tokenization and lookup. Any string or node can be passed to the function.


I sort of see why adding the /@id to the for-each select worked, but I don't know why mine didn't work or like you said didn't give me all the content.

I can't see why either ... are your referenced elements empty? Do they perhaps have an echo of the id= value in the element content?


Anyway ... it sounds like you are up and running now.

. . . . . . . . . . . . Ken


-- World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread