Altova Mailing List Archives


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

From: "Michael Kay" <mike@------------>
To:
Date: 6/16/2008 1:37:00 PM
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@xxxxxxxxx] 
> Sent: 16 June 2008 14:22
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Cc: lgfausak@xxxxxxxxx
> 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@xxxxxxxxxxxx

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.