[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] How do I pass params from and receive params from the template?


Subject: Re: [xsl] How do I pass params from <xsl:apply-templates> and receive params from the template?
From: sudheshna iyer <sudheshnaiyer@xxxxxxxxx>
Date: Sun, 3 Oct 2010 05:27:32 -0700 (PDT)

Thank you for the reply. I want the value of OLN from the document that is
being parsed as param to template.  Even if I changed "<xsl:with-param
name="param1" select="OLN"/>", I am not seeing the value printed from called
template. 

Complete files:

input1:
<?xml version="1.0"
encoding="ISO-8859-1"?>
<Order>
	<OrderLine>
			<OLN>1</OLN>
<Fname>aa</Fname>
	</OrderLine>
	<OrderLine>
			<OLN>2</OLN>
<Fname>bb</Fname>
	</OrderLine>	
</Order>


input2:
<?xml version="1.0"
encoding="ISO-8859-1"?>
<POOrder>
	<POOrderLine>
			<OLN>1</OLN>
<ID>123</ID>
			<LName>aa</LName>
	</POOrderLine>
	<POOrderLine>
<OLN>2</OLN>
			<ID>324</ID>
			<LName>bb</LName>
	</POOrderLine>
<POOrderLine>
			<OLN>3</OLN>
			<ID>456</ID>
			<LName>bb</LName>
</POOrderLine>	
</POOrder>

Xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="xml"
version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="POOrder">
<xsl:param name="param1"/>
	<xsl:value-of select="$param1"/> ====> No value
printed
</xsl:template>

<xsl:template match="Order">
<OrderResponse>
<xsl:for-each select="OrderLine">
<Oline>
	<xsl:apply-templates
select="document('file:///C:/temp/input2.xml')"/>
	<xsl:variable name="vOln">
<xsl:apply-templates select="POOrder">
			<xsl:with-param name="param1"
select="OLN"/> <===
		</xsl:apply-templates>
	</xsl:variable>
<OLN><xsl:value-of select="$vOln"/></OLN>
	<Fname><xsl:value-of
select="Fname"/></Fname>
	<Email><xsl:value-of select="Email"/></Email>
</Oline>
</xsl:for-each>
</OrderResponse>
</xsl:template>
</xsl:stylesheet>
--- On Sun, 10/3/10, David Carlisle <davidc@xxxxxxxxx> wrote:

> From: David
Carlisle <davidc@xxxxxxxxx>
> Subject: Re: [xsl] How do I pass params from
<xsl:apply-templates> and receive params from the template?
> To:
xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Cc: "sudheshna iyer"
<sudheshnaiyer@xxxxxxxxx>
> Date: Sunday, October 3, 2010, 8:07 AM
> On
03/10/2010 12:54, sudheshna iyer
> wrote:
> >        
>            
>
<xsl:apply-templates
> select="document('C:/temp/input2.xml')"/>
> 
> That is
a URI in an unknown URI scheme "C" Your xml parser
> may resolve that
correctly but if it does it is just being
> kind, not following any standards,
it should be be using the
> file URI scheme:
> file:///C:/temp/input2.xml'
>
> >        
>            
> <xsl:variable name="vOln">
> >        
>        
   
>     <xsl:apply-templates
> select="POOrder">
> >        
>            
>
        <xsl:with-param
> name="param1"><xsl:value-of
>
select="OLN"/></xsl:with-param>
> That defines $param1 to be a document node
(/) with a
> single text node child which is the string value of the OLN
>
child of the current node.
> I suspect that you intended
> <xsl:with-param
name="param1" select="OLN"/>
> which defined $param1 to be the OLN eleemnt
child of the
> current node.
> >        
>            
>        
<xsl:with-param
> name="param2">OLN</xsl:with-param>
> that defines $param2 to
be a document node with a single
> text node child with string value "OLN",
which probably
> isn't what you want here, but I'm not sure what you
>
intended.
> >        
>            
>     </xsl:apply-templates>
> >        
>
           
> </xsl:variable>
> 
> >        
>            
>
<OLN><xsl:value-of select="$vOln"/></OLN>
> 
> 
> David
> 
> 
> 
>
--~------------------------------------------------------------------
>
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To
unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail:
<mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --~--


Current Thread
Keywords
xml