implemented level=any
authorBjorn Reese <breese@src.gnome.org>
Wed, 14 Feb 2001 18:20:30 +0000 (18:20 +0000)
committerBjorn Reese <breese@src.gnome.org>
Wed, 14 Feb 2001 18:20:30 +0000 (18:20 +0000)
corrected some default values
added tests

19 files changed:
ChangeLog
libxslt/numbers.c
libxslt/transform.c
tests/REC/Makefile.am
tests/REC/test-7.7-1.out [new file with mode: 0644]
tests/REC/test-7.7-1.xml [new file with mode: 0644]
tests/REC/test-7.7-1.xsl [new file with mode: 0644]
tests/REC/test-7.7-2.out [new file with mode: 0644]
tests/REC/test-7.7-2.xml [new file with mode: 0644]
tests/REC/test-7.7-2.xsl [new file with mode: 0644]
tests/REC/test-7.7-3.out [new file with mode: 0644]
tests/REC/test-7.7-3.xml [new file with mode: 0644]
tests/REC/test-7.7-3.xsl [new file with mode: 0644]
tests/REC/test-7.7-4.out [new file with mode: 0644]
tests/REC/test-7.7-4.xml [new file with mode: 0644]
tests/REC/test-7.7-4.xsl [new file with mode: 0644]
tests/REC/test-7.7-5.out [new file with mode: 0644]
tests/REC/test-7.7-5.xml [new file with mode: 0644]
tests/REC/test-7.7-5.xsl [new file with mode: 0644]

index 32282ca..dd043ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed Feb 14 19:13:33 CET 2001 Bjorn Reese <breese@users.sourceforge.net>
+
+       * libxslt/numbers.c: implemented level=any
+       * libxslt/transform.c: corrected some default values
+       * tests/REC/test-7.7-*.*: added
+
 Wed Feb 14 18:07:25 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
 
        * libxslt/pattern.c: priorities were horribly broken, hope it's
index 63fa91b..dd0d58d 100644 (file)
@@ -398,9 +398,59 @@ xsltNumberFormatGetAnyLevel(xsltTransformContextPtr context,
                            double *array,
                            int max)
 {
-    /* preceding | ancestor-or-self */
-    TODO;
-    return 0;
+    int amount = 0;
+    int cnt = 0;
+    int keep_going = TRUE;
+    xmlNodePtr ancestor;
+    xmlNodePtr preceding;
+    xmlXPathParserContextPtr parser;
+
+    context->xpathCtxt->node = node;
+    parser = xmlXPathNewParserContext(NULL, context->xpathCtxt);
+    if (parser) {
+       /* preceding */
+       for (preceding = xmlXPathNextPreceding(parser, node);
+            preceding != NULL;
+            preceding = xmlXPathNextPreceding(parser, preceding)) {
+           if ((from != NULL) &&
+               xsltMatchPattern(context, preceding, from)) {
+               keep_going = FALSE;
+               break; /* for */
+           }
+           if (count == NULL) {
+               if ((node->type == preceding->type) &&
+                   /* FIXME: must use expanded-name instead of local name */
+                   xmlStrEqual(node->name, preceding->name))
+                   cnt++;
+           } else {
+               if (xsltMatchPattern(context, preceding, count))
+                   cnt++;
+           }
+       }
+
+       if (keep_going) {
+           /* ancestor-or-self */
+           for (ancestor = node;
+                ancestor != NULL;
+                ancestor = xmlXPathNextAncestor(parser, ancestor)) {
+               if ((from != NULL) &&
+                   xsltMatchPattern(context, ancestor, from)) {
+                   break; /* for */
+               }
+               if (count == NULL) {
+                   if ((node->type == ancestor->type) &&
+                       /* FIXME */
+                       xmlStrEqual(node->name, ancestor->name))
+                       cnt++;
+               } else {
+                   if (xsltMatchPattern(context, ancestor, count))
+                       cnt++;
+               }
+           }
+       }
+       array[amount++] = (double)cnt;
+    }
+    return amount;
 }
 
 static int
@@ -437,7 +487,9 @@ xsltNumberFormatGetMultipleLevel(xsltTransformContextPtr context,
                     preceding != NULL;
                     preceding = xmlXPathNextPrecedingSibling(parser, preceding)) {
                    if (count == NULL) {
-                       if (preceding->type == ancestor->type)
+                       if ((preceding->type == ancestor->type) &&
+                           /* FIXME */
+                           xmlStrEqual(preceding->name, ancestor->name))
                            cnt++;
                    } else {
                        if (xsltMatchPattern(context, preceding, count))
@@ -554,18 +606,16 @@ xsltNumberFormat(xsltTransformContextPtr ctxt,
                                              output);
            }
        } else if (xmlStrEqual(data->level, "any")) {
-           double numarray[1024];
-           int max = sizeof(numarray)/sizeof(numarray[0]);
            amount = xsltNumberFormatGetAnyLevel(ctxt,
                                                 node,
                                                 data->count,
                                                 data->from,
-                                                numarray,
-                                                max);
+                                                &number,
+                                                1);
            if (amount > 0) {
                xsltNumberFormatInsertNumbers(data,
-                                             numarray,
-                                             amount,
+                                             &number,
+                                             1,
                                              &array,
                                              array_amount,
                                              output);
index 61f40cc..990b440 100644 (file)
@@ -954,6 +954,13 @@ xsltNumber(xsltTransformContextPtr ctxt,
        numdata.groupingCharacter = 0;
     }
 
+    /* Set default values */
+    if (numdata.value == NULL) {
+       if (numdata.level == NULL) {
+           numdata.level = xmlStrdup(BAD_CAST("single"));
+       }
+    }
+    
     xsltNumberFormat(ctxt, &numdata, node);
 
     if (numdata.level != NULL)
index 9541527..733a5ac 100644 (file)
@@ -45,6 +45,11 @@ EXTRA_DIST =                                                 \
     test-7.6.1-2.out test-7.6.1-2.xml test-7.6.1-2.xsl \
     test-7.6.1-3.out test-7.6.1-3.xml test-7.6.1-3.xsl \
     test-7.6.2-1.out test-7.6.2-1.xml test-7.6.2-1.xsl \
+    test-7.7-1.out test-7.7-1.xml test-7.7-1.xsl        \
+    test-7.7-2.out test-7.7-2.xml test-7.7-2.xsl        \
+    test-7.7-3.out test-7.7-3.xml test-7.7-3.xsl        \
+    test-7.7-4.out test-7.7-4.xml test-7.7-4.xsl        \
+    test-7.7-5.out test-7.7-5.xml test-7.7-5.xsl        \
     test-8-1.out test-8-1.xml test-8-1.xsl             \
     test-9.1-1.out test-9.1-1.xml test-9.1-1.xsl       \
     test-9.1-2.out test-9.1-2.xml test-9.1-2.xsl       \
diff --git a/tests/REC/test-7.7-1.out b/tests/REC/test-7.7-1.out
new file mode 100644 (file)
index 0000000..e587df0
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>
+<p>1. First</p>
+<p>2. Fourth</p>
+<p>3. Second</p>
+<p>4. Third</p>
diff --git a/tests/REC/test-7.7-1.xml b/tests/REC/test-7.7-1.xml
new file mode 100644 (file)
index 0000000..ceacea5
--- /dev/null
@@ -0,0 +1,6 @@
+<items>
+  <item>First</item>
+  <item>Second</item>
+  <item>Third</item>
+  <item>Fourth</item>
+</items>
diff --git a/tests/REC/test-7.7-1.xsl b/tests/REC/test-7.7-1.xsl
new file mode 100644 (file)
index 0000000..71778db
--- /dev/null
@@ -0,0 +1,15 @@
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template match="items">
+  <xsl:for-each select="item">
+    <xsl:sort select="."/>
+    <p>
+      <xsl:number value="position()" format="1. "/>
+      <xsl:value-of select="."/>
+    </p>
+  </xsl:for-each>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/REC/test-7.7-2.out b/tests/REC/test-7.7-2.out
new file mode 100644 (file)
index 0000000..ff9da59
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+
+  
+    
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">1. First</fo:block>
+
+    
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">2. Second</fo:block>
+
+    
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">3. Third</fo:block>
+
+    
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">4. Fourth</fo:block>
+
+  
+
diff --git a/tests/REC/test-7.7-2.xml b/tests/REC/test-7.7-2.xml
new file mode 100644 (file)
index 0000000..06e9953
--- /dev/null
@@ -0,0 +1,8 @@
+<list>
+  <ol>
+    <item>First</item>
+    <item>Second</item>
+    <item>Third</item>
+    <item>Fourth</item>
+  </ol>
+</list>
diff --git a/tests/REC/test-7.7-2.xsl b/tests/REC/test-7.7-2.xsl
new file mode 100644 (file)
index 0000000..99b369a
--- /dev/null
@@ -0,0 +1,12 @@
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:fo="http://www.w3.org/1999/XSL/Format">
+
+<xsl:template match="ol/item">
+  <fo:block>
+    <xsl:number/><xsl:text>. </xsl:text><xsl:apply-templates/>
+  </fo:block>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/REC/test-7.7-3.out b/tests/REC/test-7.7-3.out
new file mode 100644 (file)
index 0000000..d42b4e1
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+
+  
+    
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">1.First Chapter</fo:block>
+
+      Here is some text.
+    
+      
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">1.1 First Chapter, First Section</fo:block>
+
+        More text here.
+      
+        
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">1.1 First Chapter, First Section, First Subsection</fo:block>
+
+      
+      
+        
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">1.1 First Chapter, First Section, Second Subsection</fo:block>
+
+      
+    
+  
+  
+    
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">2.Second Chapter</fo:block>
+
+  
+  
+    
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">A.First Appendix</fo:block>
+
+    
+      
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">A.1 First Appendix, First Section</fo:block>
+
+    
+  
+  
+    
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">B.Second Appendix</fo:block>
+
+  
+
diff --git a/tests/REC/test-7.7-3.xml b/tests/REC/test-7.7-3.xml
new file mode 100644 (file)
index 0000000..cd42869
--- /dev/null
@@ -0,0 +1,28 @@
+<book>
+  <chapter>
+    <title>First Chapter</title>
+      Here is some text.
+    <section>
+      <title>First Chapter, First Section</title>
+        More text here.
+      <subsection>
+        <title>First Chapter, First Section, First Subsection</title>
+      </subsection>
+      <subsection>
+        <title>First Chapter, First Section, Second Subsection</title>
+      </subsection>
+    </section>
+  </chapter>
+  <chapter>
+    <title>Second Chapter</title>
+  </chapter>
+  <appendix>
+    <title>First Appendix</title>
+    <section>
+      <title>First Appendix, First Section</title>
+    </section>
+  </appendix>
+  <appendix>
+    <title>Second Appendix</title>
+  </appendix>
+</book>
diff --git a/tests/REC/test-7.7-3.xsl b/tests/REC/test-7.7-3.xsl
new file mode 100644 (file)
index 0000000..3d4c9a8
--- /dev/null
@@ -0,0 +1,24 @@
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:fo="http://www.w3.org/1999/XSL/Format">
+
+<xsl:template match="title">
+  <fo:block>
+    <xsl:number level="multiple"
+                count="chapter|section|subsection"
+                format="1.1 "/>
+    <xsl:apply-templates/>
+  </fo:block>
+</xsl:template>
+
+<xsl:template match="appendix//title" priority="1">
+  <fo:block>
+    <xsl:number level="multiple"
+                count="appendix|section|subsection"
+                format="A.1 "/>
+    <xsl:apply-templates/>
+  </fo:block>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/REC/test-7.7-4.out b/tests/REC/test-7.7-4.out
new file mode 100644 (file)
index 0000000..4d49406
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+
+  
+    
+      
+       
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">1) A note here</fo:block>
+
+       
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">2) And here</fo:block>
+
+      
+      
+      
+    
+  
+  
+    
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">2) And another note here</fo:block>
+
+  
+
diff --git a/tests/REC/test-7.7-4.xml b/tests/REC/test-7.7-4.xml
new file mode 100644 (file)
index 0000000..f7e8f9e
--- /dev/null
@@ -0,0 +1,15 @@
+<book>
+  <chapter>
+    <section>
+      <subsection>
+       <note>A note here</note>
+       <note>And here</note>
+      </subsection>
+      <subsection>
+      </subsection>
+    </section>
+  </chapter>
+  <chapter>
+    <note>And another note here</note>
+  </chapter>
+</book>
diff --git a/tests/REC/test-7.7-4.xsl b/tests/REC/test-7.7-4.xsl
new file mode 100644 (file)
index 0000000..5f15af1
--- /dev/null
@@ -0,0 +1,13 @@
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:fo="http://www.w3.org/1999/XSL/Format">
+
+<xsl:template match="note">
+  <fo:block>
+    <xsl:number level="any" from="chapter" format="(1) "/>
+    <xsl:apply-templates/>
+  </fo:block>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/tests/REC/test-7.7-5.out b/tests/REC/test-7.7-5.out
new file mode 100644 (file)
index 0000000..5d7d659
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+
+  
+    
+      
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">1.1.1 one</fo:block>
+
+      
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">1.1.2 two</fo:block>
+
+      
+<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format">1.1.3 three</fo:block>
+
+    
+  
+
diff --git a/tests/REC/test-7.7-5.xml b/tests/REC/test-7.7-5.xml
new file mode 100644 (file)
index 0000000..8a5e753
--- /dev/null
@@ -0,0 +1,9 @@
+<H1>
+  <H2>
+    <H3>
+      <H4>one</H4>
+      <H4>two</H4>
+      <H4>three</H4>
+    </H3>
+  </H2>
+</H1>
diff --git a/tests/REC/test-7.7-5.xsl b/tests/REC/test-7.7-5.xsl
new file mode 100644 (file)
index 0000000..b3dfa99
--- /dev/null
@@ -0,0 +1,18 @@
+<xsl:stylesheet
+  version="1.0"
+  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:fo="http://www.w3.org/1999/XSL/Format">
+
+<xsl:template match="H4">
+  <fo:block>
+    <xsl:number level="any" from="H1" count="H2"/>
+    <xsl:text>.</xsl:text>
+    <xsl:number level="any" from="H2" count="H3"/>
+    <xsl:text>.</xsl:text>
+    <xsl:number level="any" from="H3" count="H4"/>
+    <xsl:text> </xsl:text>
+    <xsl:apply-templates/>
+  </fo:block>
+</xsl:template>
+
+</xsl:stylesheet>