 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 10th, 2009, 10:52 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Problem with template
Hi All,
how can i use template inside a template. Like below example.
Code:
<xsl:template name="Interest">
<xsl:template match="Apply">
... some code here
</xsl:template>
Thanks
Nelly
|
|

November 10th, 2009, 11:06 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
You can't, as xsl:template is a top level declaration.
If you explain what you are trying to accomplish (i.e. show us your input XML, and a sample output XML) then we can probably tell you how to do what you want.
|
|

November 10th, 2009, 11:25 AM
|
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Hi sam... thanks for your reply.
What i am trying to do is i have created a name template in that template i am receiving parameters from call template. In name template i want to compare values of attribute in xml document with parameter values.
below is the code:
Code:
<xsl:template match="Apply">
<xsl:call-template name="Activity">
<xsl:with-param name="ID">
<xsl:apply-templates select="./user/@ID"/>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="Activity">
<xsl:param name="ID"/>
<xsl:apply-templates select="document('employee.xml')"/>
<xsl:template match="employee">
<xsl:if test="@ID=$ID">
<xsl:value-of select="profile/title"></xsl:value-of>
</xsl:if>
</xsl:template>
</xsl:template>
I want to compare the value and read the data from XMl document.
Thanks
|
|

November 10th, 2009, 11:38 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
I have no idea - I said to show us your input XML, and what you want your output XML to look like. I have no idea what they look like so I can only imagine how the above is incorrect.
|
|

November 10th, 2009, 11:44 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
I think you might want
Code:
<xsl:template name="Activity">
<xsl:param name="ID"/>
<xsl:apply-templates select="document('employee.xml')//employee[@ID = $ID]"/>
</xsl:template>
<xsl:template match="employee">
<xsl:value-of select="profile/title"></xsl:value-of>
</xsl:template>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|
The Following 2 Users Say Thank You to Martin Honnen For This Useful Post:
|
|
|

November 10th, 2009, 12:15 PM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Hi Marin... Thank you very much.
You are absolutly right, i wanted the same think and its working perfectly for my scenario.
Thanks Again.
|
|

November 10th, 2009, 12:29 PM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Hi Martin,
Just a quick question in below code, how can i access 'name' parameter in the last template.
Code:
<xsl:template match="Apply">
<xsl:call-template name="Activity">
<xsl:with-param name="ID">
<xsl:apply-templates select="./dept/@name"/>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="Activity">
<xsl:param name="ID"/>
<xsl:param name="Name"/>
<xsl:apply-templates select="document('employee.xml')"/>
</xsl:template>
<xsl:template match="department">
<xsl:if test="@name=$name">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
'name' parameter is coming from call template.
Thanks
Nelly
|
|

November 10th, 2009, 12:53 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Both xsl:call-template and xsl:apply-templates allow you to pass on parameters thus you can pass parameters on. If you use XSLT 2.0 you can use tunnel parameters to ensure the parameters are passed on even if you don't explicitly do that e.g.
Code:
<xsl:template name="Activity">
<xsl:param name="ID"/>
<xsl:param name="Name"/>
<xsl:apply-templates select="document('employee.xml')">
<xsl:with-param name="Name" select="$Name" tunnel="yes"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="department">
<xsl:param name="Name" tunnel="yes"/>
<xsl:if test="@name = $Name">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

November 11th, 2009, 11:07 AM
|
|
Authorized User
|
|
Join Date: Apr 2008
Posts: 85
Thanks: 10
Thanked 0 Times in 0 Posts
|
|
Hi Matin than for your reply..
There is a little problem in parameter value:
In the below code i can see the value in '$Name'
Code:
<xsl:template name="Activity">
<xsl:param name="ID"/>
<xsl:param name="Name"/>
<xsl:apply-templates select="document('employee.xml')">
<xsl:with-param name="Name" select="$Name" tunnel="yes"/>
</xsl:apply-templates>
</xsl:template>
But here value '$Name' is showing empty:
Code:
<xsl:template match="department">
<xsl:param name="Name" tunnel="yes"/>
<xsl:if test="@name = $Name">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>
where i am doing wrong?
Thanks
Nelly
|
|

November 11th, 2009, 11:23 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Are you using XSLT 2.0 with an XSLT 2.0 processor like Saxon 9 or AltovaXML tools? Tunnel parameters are a new feature in XSLT 2.0.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|
 |