[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: Constructing documents from many sources
Subject: Re: Constructing documents from many sources
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 23 Aug 2006 10:08:55 -0400
|
Steve,
Of course it's hard to say more without seeing more, but this doesn't
look as bad to me as it apparently does to you.
Nonetheless there are a few easy things you can do to refactor and
thus save yourself a few cycles (both reading/interpreting and
maintaining the stylesheet, and perhaps even running it).
For example, your variable bindings to set up the set of source
documents contain various repetitions, such as the concatenation of
$root with '/Consumers/Reports/performance.asp?module='. That could
be bound to a variable and referenced instead of being stated it
repeatedly as a literal:
<xsl:variable name="source-module"
select="concat($root,'/Consumers/Reports/performance.asp?module=')"/>
Then
<xsl:variable name="v2B"
select="document(concat($source-module,'2B','&startDate=',$startDate,'&endDate=',$endDate))"/>
Likewise perhaps with certain parameter-value pairs designated by
'&startDate=' and '&endDate=':
<xsl:variable name="date-params"
select="concat('&startDate=',$startDate,'&endDate=',$endDate)"/>
<xsl:variable name="v2B"
select="document(concat($source-module,'2B',$date-params))"/>
... which will neaten things up a bit further. Notice this really all
amounts to syntax sugar, but if your DB API ever changes it'll also
be easier to adjust.
Similarly if your use of these documents is completely regular. For
example, if your use of $vP2 is always $vP2/Records/Record, you could
bind that into the variable up front:
<xsl:variable name="vP2records"
select="document(concat($source-module,'2B',$date-params))/Record/Records"/>
... and then vP2records contains the Record elements themselves
rather than the root of the document that contains them. Then use
$vP2records throughout your stylesheet and just drop $vP2 if it's not needed.
This kind of thing will enable you to neaten up your code considerably.
Cheers,
Wendell
At 01:13 PM 8/22/2006, you wrote:
I'll keep it brief so as to actually get an answer. The XML examples
are quite long. Sorry.
I have a very long gov't document which has a plethora of questions. I
set up all of the variables in the beginning (calling a script with a
code that tells it which SQL statement to execute and serve up as
XML).
The whole thing is just starting to seem insane to me. I wonder if the
below looks amateurish to anyone else.
Any comments are much appreciated
*Sample of initial database calls* ========
<xsl:variable name="v2B"
select="document(concat($root,'/Consumers/Reports/performance.asp?module=','2B','&startDate=',$startDate,'&endDate=',$endDate))"
/>
<xsl:variable name="vP2"
select="document(concat($root,'/Consumers/Reports/performance.asp?module=','P2','&startDate=',$startDate,'&endDate=',$endDate))"
/>
<xsl:variable name="vP2age"
select="document(concat($root,'/Consumers/Reports/performance.asp?module=','P2age','&startDate=',$startDate,'&endDate=',$endDate))"
/>
<xsl:variable name="vP2county"
select="document(concat($root,'/Consumers/Reports/performance.asp?module=','P2county','&startDate=',$startDate,'&endDate=',$endDate))"
/>
<xsl:variable name="vP2disab"
select="document(concat($root,'/Consumers/Reports/performance.asp?module=','P2disab','&startDate=',$startDate,'&endDate=',$endDate))"
/>
*Sample application of above variables* ==========
<h3>Section D - IL Plans and Waivers</h3>
<table summary="" border="1">
<tr>
<td>ILP Waived</td>
<td><xsl:value-of
select="count($vP2/Records/Record[ILPwaiver='False'])" /></td>
</tr>
<tr>
<td>ILP Developed</td>
<td><xsl:value-of
select="count($vP2/Records/Record[ILPwaiver!='False'])" /></td>
</tr>
<tr>
<td>Total</td>
<td><xsl:value-of
select="count($vP2/Records/Record[ILPwaiver='False']) +
count($vP2/Records/Record[ILPwaiver!='False'])" /></td>
</tr>
</table>
<h3>Section E - Age</h3>
<table summary="" border="1">
<tr>
<td>Under 5 years old</td>
<td><xsl:value-of
select="$vP2age/Records/Record[cat = 'Under 5
years old']/count" /></td>
</tr>
<tr>
<td>Ages 5 - 19</td>
<td><xsl:value-of select="$vP2age/Records/Record[cat = '5 -
19']/count" /></td>
</tr>
<tr>
<td>Ages 20 - 24</td>
<td><xsl:value-of select="$vP2age/Records/Record[cat = '20 -
24']/count" /></td>
</tr>
<tr>
<td>Ages 25 - 59</td>
<td><xsl:value-of select="$vP2age/Records/Record[cat = '25 -
59']/count" /></td>
</tr>
<tr>
<td>Ages 60 and older</td>
<td><xsl:value-of
select="$vP2age/Records/Record[cat = '60 and
older']/count" /></td>
</tr>
<tr>
<td>Total</td>
<td><xsl:value-of
select="sum($vP2age/Records/Record[prior='']/count)" /></td>
</tr>
</table>
<h3>Section F - Sex</h3>
<table border="1">
<tr>
<td>(1) Number of females served</td>
<td><xsl:value-of select="count($vP2/Records/Record[gender =
'female' or gender = 'F'])" /></td>
</tr>
<tr>
<td>(2) Number of males served</td>
<td><xsl:value-of select="count($vP2/Records/Record[gender =
'male'or gender = 'M'])" /></td>
</tr>
</table>
|
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
RSS 2.0 |
|
Atom 0.3 |
|
|