[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: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 29 May 2009 19:59:07 +0100
RE:  applying templates out of a for-each
xsl:for-each changes the context. If you want to use the original context
within the for-each, you need to first bind it to a variable, for example:

  <xsl:variable name="this" select="."/>
  <xsl:for-each select="....">
     <xsl:apply-templates select="$this/(//*[name()=...])"/>

Regards,

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

> -----Original Message-----
> From: Detlef Heyn [mailto:detlef.heyn@xxxxxxxxx] 
> Sent: 29 May 2009 19:29
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  applying templates out of a for-each
> 
> Hi my dear experts
> 
> 
> I would appreciate your help with a problem i have.
> 
>  From a xml file i read the content of an element wich i 
> interpret in many possible ways for it's a config file for my 
> stylesheet.
> 
> This info i give to a template as a parameter simply called "input".
> 
> One way i interpret the value is as an element name wich 
> content i want to select.
> 
> This works fine until i use the following code:
> 
> ==================================================
> <config-input>show_element:Elementname</config-input>
> =========================
> <xsl:template name="select">
>   <xsl:param name="input"/>
>   <xsl:choose>
>    ...
>    <!-- show element -->
>    <xsl:when test="contains($input,'show_element:')">
> 
>     <xsl:apply-templates select="//node()[name() = 
> substring-after($input,':')]" mode="pure"/>
> 
>    </xsl:when>
>     ...
>   </xsl:choose>
> </xsl:template>
> =========================
> 
> 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"
> 
> ==================================================
> <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)
> 
> 
> * Do I guess right or don't i catch the real cause?
> 
> * And how, if possible, do i get it work as intented?
> (I'm afraid I've just overseen a simple thing)
> 
> 
> 
> Thanks a lot for your help in advance.
> 
> have a good time
> 
> D. Heyn

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.