Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old August 17th, 2010, 08:17 AM
Authorized User
 
Join Date: Aug 2010
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default <apply-template select> causing problem

When I use only <xsl:apply-templates/> the template for child is invoked/applied. But if I use select with path(as in code below) the template is not invoked.
Kindly help.

The XML file is

Code:
<?xml version="1.0" encoding="utf-8" ?>
<OrderPrice>
  <Orderstack title="OS 1" code="OS 1" expanded="true">
    <Order title="ord1"/>
    <Order title="ord2"/>
  </Orderstack>
</OrderPrice>
Code:
<xsl:template match="/OrderPrice">
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td>
            <xsl:apply-templates select="Order">
            <xsl:with-param name="depth" select="1"/>  
          </xsl:apply-templates>
        </td>
      </tr>
    </table>
  </xsl:template>


<xsl:template match ="Orderstack">
    <xsl:param name="depth"/>
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <!-- If first level of depth, do not shift of $param-shift-width-->
        <xsl:if test="$depth>1">
          <td width="{$param-shift-width}"/>
        </xsl:if>
        <td>
          <xsl:if test="@expanded">
            <xsl:if test="@expanded='true'">
              Minus
            </xsl:if>
            <!-- plus (+) otherwise-->
            <xsl:if test="@expanded='false'">
              Plus
            </xsl:if>
          </xsl:if>
          <xsl:if test="not(@expanded)">
            <xsl:if test="$param-deploy-treeview = 'true'">
              Minus
            </xsl:if>
            <xsl:if test="$param-deploy-treeview = 'false' or not(@expanded)">
              Plus
            </xsl:if>
          </xsl:if>
          <xsl:value-of select ="@title"/>

          <xsl:apply-templates select="OrderStack">
            <xsl:with-param name="depth" select="$depth+1"/>
          </xsl:apply-templates>
          <xsl:apply-templates select="Order"/>
          
        </td>
      </tr>
    </table>
          
  </xsl:template>
 
Old August 17th, 2010, 08:22 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Well in your template for OrderPrice you have xsl:apply-templates select="Order" but your OrderPrice element does not have any "Order" child elements so nothing happens. I am not sure what you want to achieve, maybe you xsl:apply-templates select="Orderstack" to process that child element.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 17th, 2010, 08:59 AM
Authorized User
 
Join Date: Aug 2010
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default re:

sorry the order template contains following
<xsl:template match="/OrderPrice">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<xsl:apply-templates select="Orderstack">
<xsl:with-param name="depth" select="1"/>
</xsl:apply-templates>
</td>
</tr>
</table>
</xsl:template>

instead of the one in previous code.
 
Old August 17th, 2010, 09:10 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If I define the two variables you have used ($param-shift-width and $param-deploy-treeview) then it outputs various bits of XML. So to say it does 'nothing' wouldn't be true.

However you don't say what you expect the output to look like so from what I can see it works fine.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 17th, 2010, 09:33 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Please post the complete input xml, your xslt code and the output you expect.
__________________
Rummy
 
Old August 18th, 2010, 01:54 AM
Authorized User
 
Join Date: Aug 2010
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Default re:

The xml file is the complete file with same nodes repeated as I've given. What I meant to say was when I debug the xslt through vs 2008 the control doesn't pass to template of orderstack, which tells that during execution the template is not invoked.
 
Old August 18th, 2010, 03:29 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

I do not have vs2008. So post your complete xslt code atleast. just copy the code from your xslt file and paste it here. We could give a check to that. In the below snippet
Code:
<xsl:apply-templates select="OrderStack">
            <xsl:with-param name="depth" select="$depth+1"/>
</xsl:apply-templates>
OrderStack should be Orderstack. So that way there could be a small error somewhere.
__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl template killing my <sup>DHA</sup> why?? DanBe XML 5 July 20th, 2010 11:42 AM
Beginner help: <xsl:apply-template> spits out everything then does the correct match makks XSLT 4 December 21st, 2009 11:05 AM
Mutiple <select..> with XML problem ousys .NET Framework 2.0 0 November 11th, 2007 03:37 AM
Doubt in XPATH synax in <xsl:apply-templates > rajatake XSLT 3 May 4th, 2006 06:30 AM
<href> causing problems mahulda ASP.NET 1.0 and 1.1 Basics 5 July 15th, 2004 12:15 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.