xsl-list
[Top] [All Lists]

RE: [xsl] apply-templates vs. call-template problem

2008-06-16 06:37:12
There is no "select" attribute on xsl:call-template. If this isn't being
reported as an error in your stylesheet then you need to raise a bug report
on xsltproc - it's a conformance requirement that such errors be reported.

The only way to change the context node when calling xsl:call-template is

<xsl:for-each select="$top">
  <xsl:call-template name="xyz"/.
</xsl:for-each>

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

-----Original Message-----
From: Greg Fausak [mailto:lgfausak(_at_)gmail(_dot_)com] 
Sent: 16 June 2008 14:22
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Cc: lgfausak(_at_)gmail(_dot_)com
Subject: [xsl] apply-templates vs. call-template problem

Hi,

I'm using xsltproc on freebsd. I've encountered a problem 
that I think is because I don't understand xsl/xml 
namespaces?  Anyway, I got my xsl stylesheet to work below 
using the template:

<xsl:stylesheet version="1.0"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
       xmlns:str="http://exslt.org/strings";
       xmlns:set="http://exslt.org/sets";
       xmlns:regexp="http://exslt.org/regular-expressions";
       xmlns:exslt="http://exslt.org/common";
       xsl:extension-element-prefixes="str set regexp exslt"
       >
<xsl:output method="text" indent="no"/>

<xsl:template match="/schema">
                               <xsl:call-template name="create-groups"
select="."/>
                               <xsl:call-template 
name="create-partitions" select="."/>
                               <xsl:apply-templates 
select="tables/table"/>
                               <xsl:call-template 
name="table-permissions" select="."/>
                               <xsl:call-template name="table-indices"
select="."/>
                              <xsl:call-template name="oid-indices"
select="$top/schema"/>
</xsl:template>

I then decided it would be nice to just call each template if 
a command line flag was specified, but, I can't get it to 
work for the call-template variety.  The apply-templates 
seems to work if I create an anchor $top variable to 'reselect'....

<xsl:stylesheet version="1.0"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
       xmlns:str="http://exslt.org/strings";
       xmlns:set="http://exslt.org/sets";
       xmlns:regexp="http://exslt.org/regular-expressions";
       xmlns:exslt="http://exslt.org/common";
       xsl:extension-element-prefixes="str set regexp exslt"
       >
<xsl:param name="actions"
select="string('groups,partitions,tables,tablepermissions,tabl
eindices,oidindices')"/>
<xsl:output method="text" indent="no"/>

<xsl:template match="/schema">
       <xsl:variable name="top" select="."/>
       <xsl:for-each select="str:tokenize($actions, ',')">
               <xsl:choose>
                       <xsl:when test=". = 'groups'">
                               <xsl:text>got groups&#xa;</xsl:text>
                               <xsl:call-template name="create-groups"
select="."/>
                       </xsl:when>
                       <xsl:when test=". = 'partitions'">
                               <xsl:text>got 
partitions&#xa;</xsl:text>
                               <xsl:call-template 
name="create-partitions" select="$top"/>
                       </xsl:when>
                       <xsl:when test=". = 'tables'">
                               <xsl:text>got tables&#xa;</xsl:text>
                               <xsl:apply-templates 
select="$top/tables/table" mode='tables'/>
                       </xsl:when>
                       <xsl:when test=". = 'tablepermissions'">
                               <xsl:text>got 
tablepermissions&#xa;</xsl:text>
                               <xsl:call-template 
name="table-permissions" select="."/>
                       </xsl:when>
                       <xsl:when test=". = 'tableindices'">
                               <xsl:text>got 
tableindices&#xa;</xsl:text>
                               <xsl:call-template name="table-indices"
select="."/>
                       </xsl:when>
                       <xsl:when test=". = 'oidindices'">
                               <xsl:text>got 
oidindices&#xa;</xsl:text>
                               <xsl:apply-templates 
select="$top/tables/table" mode='oid-indices'/>
<!--                            <xsl:call-template name="oid-indices"
select="$top/schema"/> -->
                       </xsl:when>
                       <xsl:otherwise>
                               <xsl:message terminate="yes"> 
UNKNOWN command line argument: <xsl:value-of select="."/>
                               </xsl:message>
                       </xsl:otherwise>
               </xsl:choose>
       </xsl:for-each>

</xsl:template>

In this example just the 'apply-templates' calls work.  The 
'call-template'
fires, but I can't seem to 'select' the /schema tree.

In both cases my xml data looks like:

<schema name="ad_schema" database="ad_voip"> <tables>
  <table name="at_address" perm="superuser">
    <comments>
      Address
      This is an address record.
      It is normally included in other record's views.
    </comments>
    <fields>
<field is_nullable="1" data_type="text" name="ac_b" >
        <comments>
          Brand ID
          This address belongs to this brand.
        </comments>
      </field>

...



Thank you,
---greg


--
Greg Fausak
greg(_at_)thursday(_dot_)com

--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--