[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: applying templates out of a for-each

Subject: Re: applying templates out of a for-each
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 29 May 2009 14:34:15 -0400
Re:  applying templates out of a for-each
At 2009-05-29 20:28 +0200, Detlef Heyn wrote:
but if i want to apply more than one element-content with the help of a for-each over the readed config-input (wich im tokenizing to seperate the certain element names) i get this error:

"F[Saxon-B 9.0.0.6]Cannot select a node here: the context item is an atomic value
URL: http://www.w3.org/TR/xpath20/#ERRXPTY0020"

Correct, because you are not in a node tree when you are acting on the tokens from a string.


==================================================
<config-input>show_element:Elementname1 Elementname2</config-input>
=========================
<xsl:template name="select">
 <xsl:param name="input"/>
 <xsl:choose>
  ...
  <!-- show element -->
  <xsl:when test="contains($input,'show_element:')">
   <xsl:for-each select="tokenize(substring-after($input,':'),' ')">
    <xsl:variable name="temp_name" select="string(.)"/>
    <xsl:apply-templates select="//node()[name() = $temp_name]" mode="pure"/>
   </xsl:for-each>
  </xsl:when>
   ...
 </xsl:choose>
</xsl:template>
=========================

I understand that Saxon has a problem with applying templates inside of a for-each-loop wich is all about selecting atomic values (strings in this case)

It is not Saxon's problem at all! It is your problem for trying to use "/" when there is no current node.


* Do I guess right or don't i catch the real cause?

You have missed the real cause and blamed software for your own stylesheet problem.


* And how, if possible, do i get it work as intented?
(I'm afraid I've just overseen a simple thing)

Put the root node you want to use into a variable and then address off if it:


<xsl:variable name="top" select="/"/>
<xsl:for-each select="tokenize(substring-after($input,':'),' ')">
<xsl:variable name="temp_name" select="string(.)"/>
<xsl:apply-templates select="$top//node()[name() = $temp_name]" mode="pure"/>
</xsl:for-each>


BTW, your use of "name()=$temp_name" is not sensitive to namespaces, which may or may not be important to you in the long run. Look up the use of node-name() and functions returning QName values.

I hope this helps.

. . . . . . . . . . . Ken

--
XSLT/XSL-FO/XQuery hands-on training - Los Angeles, USA 2009-06-08
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.