[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Processing IDREFS attributes


Subject: Re: [xsl] Processing IDREFS attributes
From: Dan Vint <dvint@xxxxxxxxx>
Date: Tue, 01 Nov 2005 16:08:15 -0800

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.



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?


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.

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(.)"/>



and it would report a space-separated list of unique token values (rather than just @references since that might have duplicates).

If you don't have a declaration of the attribute type, then id() has nothing to look up and will always return an empty node set.

Yep, had that problem covered.



I hope this helps, Dan.

Yes, once again you have come to the rescue. 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.


..dan
---------------------------------------------------------------------------
Danny Vint

Specializing in Panoramic Images of California and the West
http://www.dvint.com

voice: 510-522-4703

When H.H. Bennett was asked why he preferred to be out
shooting landscapes rather than spending time in his portrait studio:

"It is easier to pose nature and less trouble to please."

http://www.portalwisconsin.org/bennett_feature.cfm


Current Thread