Re: [xsl] selecting an element in an external doc using its id attribute

Subject: Re: [xsl] selecting an element in an external doc using its id attribute
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Tue, 18 Jun 2002 10:02:15 +0200
Hi Jarkko,

the answer was already given by Joerg Pietschmann. In XSLT a id()-function exists, which Cindy is using (only in a wrong way). When you want to use id() you have to declare an attribute in the DTD as ID. You will have fast access to this element, which has the value given as parameter to id(). It's similar to the key(), but you don't need to construct a key(), you only need the DTD.

The problem Cindy has with her code is the writing of the expression. A function must not be written after an XPATH. So she must change the context before using id() to the other file:

<xsl:for-each select="$docnode">
  <xsl:value-of select="id($from)"/>
</xsl:for-each>

Regards,

Joerg

Jarkko.Moilanen@xxxxxx wrote:
Lainaus Cindy Mazza <clm6u@xxxxxxxxxxxx>:


Hi ,


The following code gets me the first div3 element w/in the odes document (as expected):

       <xsl:variable name="from" select="@from"/>
       <xsl:variable name="docnode"
select="document('../texts/odes.xml')"/>
       <xsl:message>
         <xsl:value-of select="$docnode//div3"/>
       </xsl:message>

But when I try to find an element whose id attribute is equal to the
value of the 'from' variable, I get an error saying "Unexpected token
[<function>] in path expression."

       <xsl:variable name="from" select="@from"/>
       <xsl:variable name="docnode"
select="document('../texts/odes.xml')"/>
       <xsl:message>
         <xsl:value-of select="$docnode//id($from)"/>
       </xsl:message>

Sorry, if I dont understand this correctly, but error is that U are looking /selecting the value of id elements from attribute. Is this what U really want? It would help to see the xml file (atleast for me).
Jeni, Michael, some other guru could correct me if I´m wrong.


Cheers
Jarkko


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread