applied patch for param visibility from Shaun McCance. Changed variable
authorWilliam M. Brack <wbrack@src.gnome.org>
Wed, 12 Nov 2003 10:20:03 +0000 (10:20 +0000)
committerWilliam M. Brack <wbrack@src.gnome.org>
Wed, 12 Nov 2003 10:20:03 +0000 (10:20 +0000)
* libexslt/functions.c: applied patch for param visibility from
  Shaun McCance.  Changed variable scoping in accordance with
  Shaun's suggestions.  This fixed problem reported on the list
  by Bernd Lang
* tests/exslt/functions/function.8.[xml,xsl,out], Makefile.am:
  regression test for above

ChangeLog
libexslt/functions.c
tests/exslt/functions/Makefile.am
tests/exslt/functions/function.8.out [new file with mode: 0644]
tests/exslt/functions/function.8.xml [new file with mode: 0644]
tests/exslt/functions/function.8.xsl [new file with mode: 0644]

index 8febe8d..25a22ea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Tue Nov 12 18:17:24 HKT 2003 William Brack <wbrack@mmm.com.hk>
+
+       * libexslt/functions.c: applied patch for param visibility from
+         Shaun McCance.  Changed variable scoping in accordance with
+         Shaun's suggestions.  This fixed problem reported on the list
+         by Bernd Lang
+       * tests/exslt/functions/function.8.[xml,xsl,out], Makefile.am:
+         regression test for above
+       
 Sat Nov  8 13:27:12 CET 2003 Daniel Veillard <daniel@veillard.com>
 
        * libexslt/libexslt.3: applied improvement patch from Jonathan Wakely
index efa6713..d4ab48c 100644 (file)
@@ -262,7 +262,8 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
     xmlXPathObjectPtr obj, oldResult, ret;
     exsltFuncData *data;
     exsltFuncFunctionData *func;
-    xmlNodePtr paramNode, oldInsert, fake;
+    xmlNodePtr paramNode, oldInsert, fake, content = NULL;
+    int oldBase;
     xsltStackElemPtr params = NULL, param;
     xsltTransformContextPtr tctxt = xsltXPathGetTransformContext(ctxt);
     int i;
@@ -289,8 +290,10 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
        ctxt->error = XPATH_INVALID_ARITY;
        return;
     }
-    if (func->content != NULL)
+    if (func->content != NULL) {
        paramNode = func->content->prev;
+       content = func->content;
+    }
     else
        paramNode = NULL;
     if ((paramNode == NULL) && (func->nargs != 0)) {
@@ -299,14 +302,13 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
                         "param == NULL\n");
        return;
     }
-    /* defaulted params */
+
+    /* set params */
     for (i = func->nargs; (i > nargs) && (paramNode != NULL); i--) {
-       param = xsltParseStylesheetCallerParam (tctxt, paramNode);
-       param->next = params;
-       params = param;
        paramNode = paramNode->prev;
+       if (content != NULL)
+           content = content->prev;
     }
-    /* set params */
     while ((i-- > 0) && (paramNode != NULL)) {
        obj = valuePop(ctxt);
        /* FIXME: this is a bit hackish */
@@ -327,9 +329,16 @@ exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
                         (const xmlChar *)"fake", NULL);
     oldInsert = tctxt->insert;
     tctxt->insert = fake;
+    /* 
+     * In order to give the function variables a new 'scope' we
+     * change varsBase in the context.
+     */
+    oldBase = tctxt->varsBase;
+    tctxt->varsBase = tctxt->varsNr;
     xsltApplyOneTemplate (tctxt, xmlXPathGetContextNode(ctxt),
-                         func->content, NULL, params);
+                         content, NULL, params);
     tctxt->insert = oldInsert;
+    tctxt->varsBase = oldBase; /* restore original scope */
     if (params != NULL)
        xsltFreeStackElemList(params);
 
index ff2e91d..d2c27c0 100644 (file)
@@ -9,7 +9,9 @@ EXTRA_DIST =                                            \
        function.3.out  function.3.xml  function.3.xsl  \
        function.4.out  function.4.xml  function.4.xsl  \
        function.5.out  function.5.xml  function.5.xsl  \
-       function.6.out  function.6.xml  function.6.xsl
+       function.6.out  function.6.xml  function.6.xsl  \
+       function.7.out  function.7.xml  function.7.xsl  \
+       function.8.out  function.8.xml  function.8.xsl
 
 all:
 
diff --git a/tests/exslt/functions/function.8.out b/tests/exslt/functions/function.8.out
new file mode 100644 (file)
index 0000000..745ace7
--- /dev/null
@@ -0,0 +1,2 @@
+typedef struct Pcmdb_TestHeadDatabase Pcmdb_TestHeadDatabase; 
+
diff --git a/tests/exslt/functions/function.8.xml b/tests/exslt/functions/function.8.xml
new file mode 100644 (file)
index 0000000..8eee16d
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+<!DOCTYPE adt SYSTEM "adt.dtd">
+-->
+
+<adt>
+
+  <prosa-name>Test Head Database</prosa-name>
+  <prefix>pcmdb</prefix>
+
+  <author>Max Mueller</author>
+  <date>August 16, 2002</date>
+  
+  <brief>This adt holds relevant information regarding the test head
+  of the tester.</brief> 
+  <detailed>
+    There is only one instance of the adt in the system, and you can
+    query the adt regarding parameters of the current installed test
+    head.
+  </detailed>
+
+</adt>
diff --git a/tests/exslt/functions/function.8.xsl b/tests/exslt/functions/function.8.xsl
new file mode 100644 (file)
index 0000000..5d46af1
--- /dev/null
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<xsl:stylesheet version="1.0" 
+       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+       xmlns:func="http://exslt.org/functions"
+            extension-element-prefixes="func"
+>
+<xsl:output method="text" encoding="ISO-8859-1" omit-xml-declaration="yes" />
+
+<xsl:variable name="prefix" select="/adt/prefix" /> 
+<xsl:variable name="prosaName" select="/adt/prosa-name" />
+
+<xsl:variable name="suffix" select="'.h'" />
+
+<!-- makes all letters upper case -->
+<func:function name="func:upper">
+  <xsl:param name="in" />
+  <func:result select="translate($in,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
+</func:function>
+
+<!-- makes all letters lower case -->
+<func:function name="func:lower">
+  <xsl:param name="in" />
+  <func:result select="translate($in,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" />
+</func:function>
+
+<!-- makes first letter (of every word) upper case -->
+<!-- converts first x to X and every _x to _X       -->
+<!-- and every ' x' to 'X' (note the space)        -->
+<func:function name="func:firstUpper">
+  <xsl:param name="in" />
+  <xsl:variable name="tmp" select="$in"/>
+  <xsl:choose>
+    <!-- Call first upper for each word -->
+    <xsl:when test="contains(substring($tmp,2),' ')">
+      <func:result select="concat(
+        func:firstUpper(substring-before($tmp,' ')),
+        func:firstUpper(substring-after(substring($tmp,2),' ')))" />
+    </xsl:when>
+    <!-- read over '_' -->
+    <xsl:when test="contains(substring($tmp,1,1),'_')">
+      <func:result select="concat('_',
+        func:firstUpper(substring($tmp,2)))" />
+    </xsl:when>
+    <!-- Make first character upper case and continue -->
+    <xsl:otherwise>
+      <func:result select="concat(func:upper(substring($tmp,1,1)),
+        substring($tmp,2))" />
+    </xsl:otherwise> 
+  </xsl:choose>
+</func:function>
+
+<xsl:template match="adt">
+
+  <xsl:variable name="prosaNameLower" select="func:lower($prosaName)" />
+
+  <xsl:value-of select="concat( 'typedef struct ', 
+    func:firstUpper($prefix), '_', func:firstUpper($prosaNameLower), ' ',
+    func:firstUpper($prefix), '_', func:firstUpper($prosaNameLower), 
+    '; &#10;&#10;' )" />
+
+</xsl:template>
+
+<!-- finished -->
+</xsl:stylesheet>