Solved

XPath trouble with attribute value in a predicate

Posted on 2003-12-01
2
421 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
2 Comments
 
LVL 9

Accepted Solution

by:
sparkplug earned 500 total points
Comment Utility
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
Comment Utility
Hi,
that worked!
I modified the LOV file a littl so I can use it for other stuff, too

Thanx.

CirTap
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VB.NET and XML parsing 6 55
Change to event 1 72
Problem to event 3 49
Create and populate iFrame onClick of a button? 1 43
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now