• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

passing vars xsl

hi guys
could you help please, i cannot find the answer...

im making a FO invoice template for some crm web-site (so i cannot really control whats inside)
and i almost completed doing that.. however i cannot pass some variable to a template::

so i want to pass @currency to <xsl:apply-templates select="LineItems/LineItem"/>
<xsl:stylesheet version="1.0" extension-element-prefixes="saxon" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ITypeFormat="java:salesorder.util.ITypeFormat" xmlns:saxon="http://icl.com/saxon">
	<xsl:param name="OBJECT"/>
	<xsl:variable name="DT" select="saxon:node-set($OBJECT)"/>
	  
	  <xsl:template match="/*">
          <!-- i can see @currency here if i display it like that -->
          <fo:block><xsl:value-of select="@currency"/></fo:block>
                    
                      <xsl:apply-templates select="LineItems/LineItem"/>             
 
         </xsl:template>
 
<!-- below is template that i want to display the variable @currency that can be displayed in above template-->
 
<xsl:template match="LineItems/LineItem"  xmlns:fo="http://www.w3.org/1999/XSL/Format">
 
         <fo:block><xsl:value-of select="@currency"/></fo:block>
 
</xsl:template>

Open in new window

0
nzrubin
Asked:
nzrubin
  • 2
1 Solution
 
Geert BormansInformation ArchitectCommented:
Here is how you can pass a parameter, if that really is what you need
<xsl:stylesheet version="1.0" extension-element-prefixes="saxon" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ITypeFormat="java:salesorder.util.ITypeFormat" xmlns:saxon="http://icl.com/saxon">
	<xsl:param name="OBJECT"/>
	<xsl:variable name="DT" select="saxon:node-set($OBJECT)"/>
	  
	  <xsl:template match="/*">
          <!-- i can see @currency here if i display it like that -->
          <fo:block><xsl:value-of select="@currency"/></fo:block>
                    
                      <xsl:apply-templates select="LineItems/LineItem"/>             
 
         </xsl:template>
 
<!-- below is template that i want to display the variable @currency that can be displayed in above template-->
 
<xsl:template match="LineItems/LineItem"  xmlns:fo="http://www.w3.org/1999/XSL/Format">
 
         <fo:block><xsl:value-of select="@currency"/></fo:block>
 
</xsl:template>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
But you could easily look higher up the tree

the xpath expression /* sends you back to the root element
using /@currency, you get the currency attribute of that element

There are many axes in XPath, so you could go looking for data in all sorts of directions,
the only reason why you want to pass this as a parameter, is when you thing that looking-up-the-tree is going to be very expensive


    <xsl:template match="LineItems/LineItem"  xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <xsl:param name="currency"></xsl:param>
        
        <fo:block><xsl:value-of select="/*/@currency"/></fo:block>
        
    </xsl:template>

Open in new window

0
 
nzrubinAuthor Commented:

this is work just fine! of course! /*/@currency"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now