Solved

XPath trouble with attribute value in a predicate

Posted on 2003-12-01
2
422 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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…
The viewer will learn how to count occurrences of each item in an array.

929 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