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

Which structure is better?

Subject: Which structure is better?
From: "james walker" <jameswalkerandy@xxxxxxxxxxx>
Date: Wed, 28 Jan 2004 15:53:23 +0000
capkeys 1.2
Sorry for the long message, I have these 2 xml files.
xml file 1:
<allcat>
<cat><name></name></desc></desc><req key="1.1.1"/></cat>
<cat><name></name></desc></desc><req key"1.2.2" /><req key"1.5.2" /></cat>
<cat><name></name></desc></desc>><req key"1.1.2" /><req key"4.2.2" /></cat>
</allcat>

xml file 2:
<cap>
<sec key="1"><subsec key="1"><req key="1"></req><req key="2"></req></subsec><subsec key="2"><req key="3"></req></subsec></sec>
<sec key="2">.........</sec>
</cap>


I have created an xslt which outputs the category names (from xml file 1) and uses the requirement keys to print the details of each requirement (from xml file 2).

the xsl file is translated with xml file 1, i came up with two designs which produce the same results but i am confused as to which would be better and why?

teh first design is:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:variable name="standard" select="document'xmlfile2.xml')" />


	<xsl:template match="allcat">
		<h1>title of page</h1>
		<xsl:apply-templates select="cat[name='name of a category']" />
	</xsl:template>

<xsl:template match="cat">
<xsl:for-each select="requirement">
<xsl:variable name="secno" select="substring-before(@key,'.')" />
<xsl:variable name="subsecno" select="substring-before(substring-after(@key,'.'),'.')" />
<xsl:variable name="reqno" select="substring-after(substring-after(@key,'.'),'.')" />
<xsl:apply-templates select="$standard/cap/sec[./@key=$secno]/subsec[./@key=$subsecno]/req[./@key=$reqno]" />
</xsl:for-each>
</xsl:template>


	<xsl:template match="chap/sec/subsec/req">
		<xsl:value-of select="name"/>
		<xsl:value-of select="description" />
	</xsl:template>

</xsl:stylesheet>

the second design is:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:variable name="standard" select="document'xmlfile2.xml')" />


	<xsl:template match="allcat">
		<h1>title of page</h1>
		<xsl:apply-templates select="cat[name='name of a category']" />
	</xsl:template>

<xsl:template match="cat">
<xsl:for-each select="requirement">
<xsl:variable name="secno" select="substring-before(@key,'.')" />
<xsl:variable name="subsecno" select="substring-before(substring-after(@key,'.'),'.')" />
<xsl:variable name="reqno" select="substring-after(substring-after(@key,'.'),'.')" />
<xsl:for-each select="$standard/cap/sec[./@key=$secno]/subsec[./@key=$subsecno]/req[./@key=$reqno]">
<xsl:value-of select="name"/>
<xsl:value-of select="description" />
</xsl:for-each>
</xsl:for-each>
</xsl:template>


</xsl:stylesheet>


I think the second one isnt as appropriate but wanted to get a second opinion, i know i probably shouldnt be fussing because i have the solution i want but i wanted to make sure i am tackliing the problem in the correct way?
I dont think the scond one is appropriate as it uses a for-each loop fo rsomething which will only ever loop once (in order to match a requirement from one to file to the corresponding requirement in the other).


_________________________________________________________________
Use MSN Messenger to send music and pics to your friends http://www.msn.co.uk/messenger



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.