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

Re: foreign keys in a xml-database

Subject: Re: foreign keys in a xml-database
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Fri, 03 May 2002 21:20:25 +0200
xml database foreign key
ChivaBaba@xxxxxxx wrote:
Hi folks,

does anybody know, whether there is a technique of defining foreign keys in a xml-database by xml or xsl??

Well, xml-database appears to be the wrong term here.

Assuming that you mean files with XML content, yes,
you can store stuff in a second file and refer to
parts of it during an XSL transformation. There is
no formal declaration of a foreign key in the sense
this term is used for RDBMS.

As example, lets say you have several documents like
this:

<primary-stuff>
  <some-stuff>
     <stuff-ref>a</stuff-ref>
     <stuff-ref>c</stuff-ref>
  </some-stuff>
  <some-more-stuff>
     <stuff-ref>b</stuff-ref>
     <stuff-ref>c</stuff-ref>
  </some-more-stuff>
</primary-stuff>

and the file where the referenced stuff is really stuffed,
i mean stored:
<stuff-base>
   <stuff><name>a</name><value>This is <b>a</b> stuff</value></stuff>
   <stuff><name>b</name><value>Some of <i>b</i> stuff</value></stuff>
   <stuff><name>c</name><value>c value</value></stuff>
</stuff-base>

You can pull in stuff values from the stuff base
during a transformation with the document() function.
The following will replace the stuff-ref elements
with the value of the referenced stuff in the output,
if properly applied:

 <xsl:template match="stuff-ref">
   <xsl:copy-of select="document('stuff-base.xml')/stuff-base/stuff[name=current()]/value"/>
 <xsl:template>

If your stuff base becomes large, you can define a key for
faster access. A key in XSLT is a similar, though not quite
the same as a primary or foreign key for RDBMS.
  <xsl:key name="stuff-ref" match="stuff" use="name"/>

 <xsl:template match="stuff-ref">
   <xsl:for-each select="document('stuff-base.xml')">
     <xsl:copy-of select="key('stuff-ref',.)/value"/>
   </xsl:for-each>
 <xsl:template>

The for-each may look like a loop, but it is actually
only used to change the context document for the key.

For further information and examples, look into your
favorite XSLT book, the XSLT spec, the mailing list
archive or the web in general for document() and xsl:key.

J.Pietschmann


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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.