[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: foreign keys in a xml-database
ChivaBaba@xxxxxxx wrote:
Hi folks,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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|