RE: [xsl] Interrogating attributes values to get text (part deaux)

Subject: RE: [xsl] Interrogating attributes values to get text (part deaux)
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 20 Mar 2009 13:17:01 -0000
David's solution looks correct to me.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Charles Flanders [mailto:cflanders@xxxxxxxxxx] 
> Sent: 20 March 2009 12:35
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Interrogating attributes values to get text 
> (part deaux)
> 
> Thank you David for your template.
> 
> My apologies for not providing a complete example of my XML. 
> In my quest to be brief, I did give a full picture of my 
> problem. The problem is that there are multiple <nameloc> 
> elements to interrogate. The template you wrote always 
> returns the value for the child of the first <nameloc>. I 
> need to interrogate each <nameloc> id value to find the one 
> that matches @linkend for the current <HYPERTEXT>. I've tried 
> creating a variable using <xsl:for-each>, and then evaluating 
> that against the value of @linkend, but I end with the the 
> first <nameloc> child "P3-11" each time.
> 
> My sample should have looked like this:
> 
> <document>
>    <nameloc id="M05-08.-HT1">
>       <nmlist nametype="element" dtdorlpd="BODY" 
> type="PARA0">P3-11</nmlist>
>    </nameloc>
>    <nameloc id="M05-08.-HT2">
>       <nmlist nametype="element" dtdorlpd="REAR" 
> docorsub="APPX-F" elemtype="ROW">item1</nmlist>
>    </nameloc>
>    <nameloc id="M05-08.-HT3">
>       <nmlist nametype="element" dtdorlpd="REAR" 
> docorsub="APPX-G" elemtype="ROW">item2</nmlist>
>    </nameloc>
>    <nameloc id="M05-08.-HT4">
>       <nmlist nametype="element" dtdorlpd="REAR" 
> docorsub="APPX-G" elemtype="ROW">item9</nmlist>
>    </nameloc>
>    <nameloc id="M05-08.-HT5">
>       <nmlist nametype="element" dtdorlpd="REAR" 
> docorsub="APPX-G" elemtype="ROW">item36</nmlist>
>    </nameloc>
> 
> 
> 
> <STEP>
>                     <HYPERTEXT linkend="M05-08.-HT2">Service
>                     air cleaner assembly.</HYPERTEXT>
>                 </STEP>
> </document>
> 
> Result to be:
> 
> 
> <step>Service air cleaner assembly.<link item="item1"></step>
> 
> 
> C Flanders
> 
> 
> 
> Date: Thu, 19 Mar 2009 18:42:13 -0400
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> From: Charles Flanders <cflanders@xxxxxxxxxx>
> Subject: Interrogating attributes values to get text
> Message-ID: <49C2CA45.60105@xxxxxxxxxx>
> 
> I could use help with problem that I just don't seem to have 
> the programming chops to conquer. I don't have template for 
> anyone to analyze, I can't seem to get to that state. I'm 
> using XSL 1.0.
> 
> Here is my conundrum:
> 
> I have an element <HYPERTEXT>, that has an attribute called 
> "linkend". 
> The value of "linkend" corresponds to an ID attribute on an 
> element further up the tree (preceding). This element is 
> named <nameloc>. This element has a child, <nmlist>.  My goal 
> is to convert <HYPERTEXT> to <link> (easy enough). But my 
> problem is I can't seem to write an expression (xsl:if? 
> xsl:when?) to can go find the <nameloc> element that has the 
> corresponding ID, then get the text of <nmlist> as the value 
> of an "item" attribute on <link>.
> 
> The following are just snippets of XML. The entire tree 
> structure should be irrelevant. Also, the <nameloc> and 
> <nmlist> elements are eliminated in the results (not 
> converted or output).
> 
> Current XML:
> 
> <document>
>     <nameloc id="M05-08.-HT2">
>         <nmlist nametype="element" dtdorlpd="REAR" docorsub="APPX-F"
>         elemtype="ROW">item1</nmlist>
>     </nameloc>
> 
> <STEP>
>                     <HYPERTEXT linkend="M05-08.-HT2">Service
>                     air cleaner assembly.</HYPERTEXT>
>                 </STEP>
> </document>
> The result I need to create is this:
> 
> <step>Service  air cleaner assembly.<link item="item1"></step>
> 
> How do I write a test will get me text of <nmlist> based on 
> the comparison of "linkend" and "id"?
> 
> Thanks.
> 
> C. Flanders
> 
> ------------------------------
> 
> Date: Thu, 19 Mar 2009 22:45:52 GMT
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> From: David Carlisle <davidc@xxxxxxxxx>
> Subject: Re: [xsl] Interrogating attributes values to get text
> Message-Id: <200903192245.n2JMjqBu032713@xxxxxxxxxxxxxxxxxxx>
> 
> <xsl:key name="id" match="nameloc" use="@id"/> <xsl:template 
> match="HYPERTEXT"> <link item="{key('id',@linkend)/nmlist}"/>
> </xsl:template>
> 
> David
> 
> --
> *C. Flanders*
> 
> <mailto:cflanders@xxxxxxxxxx>

Current Thread