Solved

XPath trouble with attribute value in a predicate

Posted on 2003-12-01
2
427 Views
Last Modified: 2013-11-19
Hi experts,
this is pretty urgent, and I'm running out of ideas.
I'm trying to call a template and pass a parameter based on the content of another node, but I can't figure out how to use an attribute of the context-node as the predicate.

Here are the relevant parts:
values_en.xml with look-up values:
<lov>
 <representations>
   <simplified>Chinese simplified</simplified>
   <pinjin>Pinjin</simplified>
   <ipa>Intl. phon. alphabet</ipy>
   <foo>Bar</foo>
 </representations>
</lov>

someplace early in the xslt file I "load" the file
<xsl:variable name="LOV">
  <xsl:copy-of select="document('values_en.xml')//lov" />
</xsl:variable>
I'm not sure if this one would be better -- they both seem to work
 <xsl:variable name="LOV" select="document('values_en.xml')//lov" />

In the XML document (call it main.xml) which is actually beeing processed I have some <element type="simplified"> .. <element type="ipa">, with their 'type' attribute matching one of the possible "representations/*" in "values_en.xml" (hope I explained tis well enough)

Now I want to use the value of element/@type, e.g. type="ipa", to find me the matching //lov/representations/ipa element and assign its content for the parameter.

Here's where I loop through some element list of main.xml to create a html table with these "translated" <representations>. Except for the parameter always being empty, everything is doing fine: the template get's called, renders, it knows all the other elements around, but $Script stays void :-(

   <xsl:for-each select="some_element_list">
      <xsl:call-template name="TABLE.TR">
         <xsl:with-param name="Script">
            <xsl:value-of select="$LOV/representations/type/@value" />
         </xsl:with-param>
      </xsl:call-template>
   </xsl:for-each>

Any suggestions?

tia.
CirTap
0
Comment
Question by:cirtap
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
sparkplug earned 500 total points
ID: 9857031
Hi,

Try the following:

 <xsl:for-each select="some_element_list">
      <xsl:call-template name="TABLE.TR">
         <xsl:with-param name="Script">
            <xsl:value-of select="$LOV/representations/*[name() = current()/@value]" />
         </xsl:with-param>
      </xsl:call-template>
   </xsl:for-each>

"$LOV/representations/*[name() = current()/@value]" selects the node under "representations" with the name equal to the current "value" attribute.

>S'Plug<
0
 
LVL 5

Author Comment

by:cirtap
ID: 9862315
Hi,
that worked!
I modified the LOV file a littl so I can use it for other stuff, too

Thanx.

CirTap
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XML to Excel using XSL - formatting 3 44
Animated .jpg? 13 114
SQL XML ALL Nodes Compare in function 2 53
Add to XML (Powershell) 1 55
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question