[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

apply-templates vs. call-template problem

Subject: apply-templates vs. call-template problem
From: "Greg Fausak" <lgfausak@xxxxxxxxx>
Date: Mon, 16 Jun 2008 08:22:24 -0500
 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,tableindices,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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.