Zigzag versus XSLT

Author: Sergey Savushkin, 2002

Zigzag (or Z pronounced "zi") language of Sav Zigzag ORDBMS has assumed complete features as language of object-relational algebra and is going to compete with more known SQL and XSLT in database and data processing applications. Some advantages of Zigzag data model: multilevel and multi-valued attributes, class inheritance, data integrity control, generalization (generation of knowledge base), - http://savtechno.com. Like XSLT - http://www.w3.org/XML/, Zigzag processes "tree" XML data model. We will discuss Zigzag application only for such data.

Example1: Class tree.

Let us declare simple data tree in XSLT and in Zigzag languages.

        A1

       /  \

     B1    C1

    /  \

  C1    C2

 

Zigzag

XSLT

A1:[B1:[C1,C2],C1];

<A1>

  <B1>

    <C1/>

    <C2/>

  </B1>

  <C1/>

</A1>

 

Following table illustrates only some Zigzag expressions for navigation in data tree.

 

Zigzag request

Result

Comment

= A1:C1;

A1:[B1:C1,C1];

Full path names of C1 descendants of A1 root element (for XSLT A1 is child of tree root)

= A1:C1|;

C1;

Simple names of C1 descendants of A1 root element

= :B1:C1;

A1:B1:C1;

Full names of C1 descendants of B1 nodes

= /C1;

[A1,A1:B1];

Parents of C1 nodes

= :A1:[C*~C2];

A1:[B1:C1,C1];

C*, except C2, descendants of A1.

Set operation of difference, the same as =[:A1:C*~:A1:C2]

= A1/C1;

[C1,B1:C1];

Path names from A1 to C1 without origin, A1 element

 

Path operation is most interesting that imparts to XSLT the algebra features. Nevertheless XSLT (like SQL) is predicate calculus language and path expressions are build-in. XSLT expressions are very cumbersome and it is clearly in the following comparison.

 

Zigzag

XSLT

= A1:C1;

<xsl:template match="/A1[.//*=C1]|/A1//*[.//*=C1]|/A1//C1">

  <xsl:copy>

    <xsl:apply-templates select="*"/>

  </xsl:copy>

</xsl:template>

= A1:C1|;

<xsl:template match="/A1">

  <xsl:for-each select=".//C1[1]">

    <xsl:copy/>

  </xsl:for-each>

</xsl:template>

 

Example2: Relation class tree

Nodes of data tree may have attributes.

 

        A1(a:"1")

       /        \

     B1(b:"1")   C1(b:"2",c:"2")

    /        \

  C1(c:"2")   C2(d:"1")

 

Zigzag

XSLT

A1(a:'1'):[

  B1(b:'1'):[

    C1(c:'2'),

    C2(d:'1')

  ],

  C1(b:'2',c:'2')

];

<A1 a="1">

  <B1 b="1">

    <C1 c="2"/>

    <C2 d="1"/>

  </B1>

  <C1 b="2" c="2"/>

</A1>

 

Look at some Zigzag requests.

 

Zigzag request

Result

Comment

= A1:(c:'2');

A1:[B1:C1,C1];

Path names of descendants of A1 root element with c:'2' attribute (c – name, 2 – value)

= :A1/(c:'2');

[B1:C1,C1];

Names of nodes with c:'2' attribute in the context of some A1 node

= A1:(b:'1',c:'2');

A1:B1:C1;

Demonstrates object approach in Zigzag, lower nodes (descendants) inherit attributes (b:'1') of ancestors

= A1:[(c:'2')=(b:'2')];

A1:C1;

Method to avoid inheritance mechanism. This set operation of intersection is the same as =[A1:(c:'2')=A1:(b:'2')]

 

Below is correspondence Zigzag and XSLT expressions with attributes.

 

Zigzag

XSLT

= A1:(c:'2');

<xsl:template match="/A1[.//*[@c=2]]|/A1//*[.//*[@c=2]]">

  <xsl:copy>

   <xsl:apply-templates select="*"/>

  </xsl:copy>

</xsl:template>

 

Example3: Document tree

First of all Zigzag was oriented for working with data/knowledge base, not document. Repeated data is feature of documents (XML documents), not knowledge. XSLT has powerful means for addressing to node via its position number. XML document, as tree of ordered and repeated nodes, may be lightly represented and in Zigzag, for example, thus:

 

Zigzag

XSLT

P:#(@N:e1):[

    #(@T:'t1'),

    #(@N:e2,a1:'1'):[

      #(@T:'t2')

    ],

    #(@N:e2,a1:'1',a2:'3'):[

      #(@T:'t3')

    ]

  ]

<e1>

  t1

  <e2 a1="1">

    t2

  </e2>

  <e2 a1="1" a2="3">

    t3

  </e2>

</e1>

 

                               P

                               |

           ____________________1(@N:e1)

          /                   / \

 1(@T:'t1')    2(@N:e2,a1:'1')   3(@N:e2,a1:'1',a2:'3')

               |                 |

               1(@T:'t2')        1(@T:'t3')

 

We used only one Zigzag representation of XML document from a lot of variants. The numbering of # elements is automatic process. Each number corresponds to a definite position of node (text or element) of XML (XSLT) data model. If XML node is text, relevant Zigzag node has relation with @T text content. When XML node is element, associated Zigzag node is related with @N element name and its attributes. Consider some Zigzag requests.

 

Zigzag request

Result

Comment

=P:(@N:e2);

P:1:[2,3];

Absolute positions of nodes (elements) with name e2.

= @T/(P:1:);

['t1','t2','t3'];

Text contents of all the descendants of first node.

= @N:(P:(@T:'t1')\);

@N:e1;

Name of parent of 't1' text node. The =P:(@T:'t1') is equal to P:1:1 position. The P:1:1\ is P:1.

= @N/((@N:e1):1^3);

e2;

Name of e1’s children having position from 1 to 3. The (@N:e1) is P:1.

$pr((a2:));

P:1:3(@N:e2,

      a1:'1',

      a2:'3'

     );

The $pr ($printRelation) procedure prints name and attributes of all the nodes with a2 attributes.

$x=P:(a1:'1');

$pl($x\|,' has ',

$x|3,' child');

1 has 3 child;

Example of using $x variable. The value of $x is P:1:3 node position. The $x| operation separates simple name from full path name.

 

No less interesting are Zigzag operations of updating database. For example to change e2 name of all the document elements, we can use following fragment.

 

@N:e21=@N:e2;

@N:e2~;

 

First statement makes e21 name and passes relation (correspondent nodes) to it from @N:e2. Last statement deletes old e2 name, else nodes will have two names (synonyms) that is allowable for Zigzag.

Remark

We listed some external Zigzag possibilities. Main is based on implementation. The Zigzag like SQL works with gigabyte databases, not small XML pages. Time of request is very short; it is essentially evident for large databases and for difficult embedded requests with more than 100 attributes. Direct combination Java™ and Zigzag ("Java/Zigzag" language - http://savtechno.com), unveils most powerful potential for Web database processing.