Confused with current context

Subject: Confused with current context
From: "Lee Barwick" <lee.barwick@xxxxxxxxxxxxxxx>
Date: Thu, 31 Aug 2000 11:38:46 -0700
Hi everyone,

I've been using the "persist to XML" features of the latest versions of 
MS-ADO to generate the results of an SQL query as an XML file which also 
contains the associated schema.  The resulting XML is pretty big and pretty 
ugly (see my XML doc).  So I've wrote a stylesheet to condense and extract 
the info which will be useful.

Everything is working fine but now I find my XSL seems bulky for what it's 
actually doing.  I blame this on branching out using the call-template 
statement during my processing and the use of parameters.  I feel that my 
XSL would be more 'streamlined' if I could do the function of the 
called-templates at the point of processing.  The problem is I can't find a 
way of passing in what I have called $fieldname into a select expression. 
 I'm sure it's possible but I cant seem to find a way to express this in 
the given context!  Can anyone help me? (I've included my original XML, XSL 
and the required XML).

Also, you'll notice from my XSL that I've writen 2 different versions of 
the template which I make the call to: both give the same results but are 
written slightly differently.  I would expect version 2 to perform better 
as the '@name=$fieldname' comparison is only done once, does anyone agree 
or disagree with this?

Thanks in advance
Lee


My source XML:

<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" 
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
	<s:Schema id="RowsetSchema">
		<s:ElementType name="row" content="eltOnly">
			<s:AttributeType name="firstname" rs:number="1" rs:nullable="true" 
rs:write="true">
				<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="20"/>
			</s:AttributeType>
			<s:AttributeType name="surname" rs:number="2" rs:nullable="true" 
rs:write="true">
				<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="30"/>
			</s:AttributeType>
			<s:AttributeType name="email" rs:number="3" rs:nullable="true" 
rs:write="true">
				<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="60"/>
			</s:AttributeType>
			<s:AttributeType name="extension" rs:number="4" rs:nullable="true" 
rs:write="true">
				<s:datatype dt:type="string" rs:dbtype="str" dt:maxLength="4"/>
			</s:AttributeType>
			<s:AttributeType name="hols" rs:number="5" rs:nullable="true" 
rs:write="true">
				<s:datatype dt:type="int" dt:maxLength="4" rs:precision="10" 
rs:fixedlength="true"/>
			</s:AttributeType>
			<s:extends type="rs:rowbase"/>
		</s:ElementType>
	</s:Schema>
	<rs:data>
		<z:row firstname="Lee" surname="Barwick" 
email="lee.barwick@xxxxxxxxxxxxxxx" extension="05" hols="14"/>
	</rs:data>
</xml>


***********************
My XSL:

<xsl:stylesheet xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" 
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" 
xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
	<xsl:template match="/">		
		<xsl:apply-templates/>
	</xsl:template>

	<xsl:template match="rs:data">
		<sample>
			<xsl:apply-templates/>
		</sample>
	</xsl:template>

	<xsl:template match="z:row">
		<xsl:apply-templates select="@*"/>
	</xsl:template>

	<xsl:template match="@*">
		<xsl:element name="{name()}">

<!-- ** Template call to version 1 or 2 follows here ** -->

			<xsl:call-template name="matchfield2">
				<xsl:with-param name="fieldname" select="name()"/>
			</xsl:call-template>

			<xsl:value-of select="."/>
		</xsl:element>
	</xsl:template>

<!-- ** I'll call this version 1 ** -->

	<xsl:template name="matchfield">
		<xsl:param name="fieldname"/>

		<xsl:attribute name="datatype">
			<xsl:value-of 
select="//s:AttributeType[@name=$fieldname]/s:datatype/@dt:type"/>
		</xsl:attribute>

		<xsl:attribute name="maxlength">
			<xsl:value-of 
select="//s:AttributeType[@name=$fieldname]/s:datatype/@dt:maxLength"/>
		</xsl:attribute>
	</xsl:template>

<!-- ** End of version 1 ** -->

<!-- ** I'll call this version 2 ** -->

	<xsl:template name="matchfield2">
		<xsl:param name="fieldname"/>

		<xsl:apply-templates select="//s:AttributeType[@name=$fieldname]"/>
	</xsl:template>

	<xsl:template match="s:datatype">
		<xsl:attribute name="datatype">
			<xsl:value-of select="@dt:type"/>
		</xsl:attribute>

		<xsl:attribute name="maxlength">
			<xsl:value-of select="@dt:maxLength"/>
		</xsl:attribute>
	</xsl:template>

<!-- ** End of version 2 ** -->
</xsl:stylesheet>


***********
Expected result XML:

<?xml version="1.0" encoding="UTF-16"?>
<sample>
	<firstname datatype="string" maxlength="20">Lee</firstname>
	<surname datatype="string" maxlength="30">Barwick</surname>
	<email datatype="string" 
maxlength="60">lee.barwick@xxxxxxxxxxxxxxx</email>
	<extension datatype="string" maxlength="4">05</extension>
	<hols datatype="int" maxlength="4">14</hols>
</sample>



Why not log on and see just how our new factory
is coming along.  Point your browser to
www.metromail-buildingsite.co.uk

*******************************************************
The information contained in this e-mail and any
files transmitted with it are confidential and
intended for the addressee only.  If you have 
received this e-mail in error please notify the 
originator or telephone 0191 554 6262.

This e-mail and any attachments have been
scanned for viruses prior to leaving MetroMail
but MetroMail will not be liable for any losses as
a result of any viruses being passed on.

If this e-mail offends in any way please forward 
it to sysadmin@xxxxxxxxxxxxxxx

MetroMail Ltd, Palmer Road, SW Ind Est, Peterlee
www.metromail.co.uk
*******************************************************


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


Current Thread