This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Newbie XSL Evaluation
- From: sicaudp at WellsFargo dot COM
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 23 Apr 2002 08:52:28 -0700
- Subject: [xsl] Newbie XSL Evaluation
- Reply-to: xsl-list at lists dot mulberrytech dot com
<Kudos>
Boy, this list is so amazing fascinating and the gurus so unbelievably
helpful. After my various experiences with java lists, this is quite a
refresher. Not a single nasty, pointless and interminable diatribe. I am in
heaven.
</Kudos>
I could not resist exposing myself to mischief. I am a newbie in XSLT and I
have written an XSL file which works fine. I was curious however to find out
how the pros would have actually done it. So here goes, I am appending the
XSL, the source XML and the expected result. As I said, it all works but it
is probably not the most efficient way to go.
Many thanks to Rob Koberg once again for getting me going in the right
direction.
TIA
Patrice Sicaud
(Sorry for the long post).
**********************************************
1- XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<!-- *** Sicaud 04-03-02 Start Changes -->
<html>
<head>
<title>
<xsl:value-of select="title"/>
</title>
<script type="text/javascript" language="JavaScript">
var SRArray = new Array();
SRArray [1] = new Array();
SRArray [2] = new Array();
SRArray [3] = new Array();
SRArray [4] = new Array();
SRArray [5] = new Array();
SRArray [6] = new Array();
SRArray [7] = new Array();
SRArray [8] = new Array();
SRArray [9] = new Array();
SRArray[10] = new Array();
<xsl:apply-templates select="SRSource/Case"/>
<!--<xsl:apply-templates select="ServiceRequest"/>-->
alert(fdfa);
</script>
</head>
<body/>
</html>
</xsl:template>
<xsl:template match="SRTransaction">
<!--******************-->
<xsl:param name="caseIndex"/>
<xsl:param name="srIndex"/>
<xsl:param name="srTranIndex"/>
<xsl:if
test="/SRSource/Case[$caseIndex]/ServiceRequest[$srIndex]/SRTransaction[$srT
ranIndex] = .">
<!-- Service request ID -->
<xsl:text>SRArray[</xsl:text>
<xsl:value-of select="$caseIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srTranIndex"/>
<xsl:text>][1] = '</xsl:text>
<xsl:value-of select="srID"/>
<xsl:text>';
</xsl:text>
<!--******************-->
<!-- Service request Resolution Code -->
<xsl:text>SRArray[</xsl:text>
<xsl:value-of select="$caseIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srTranIndex"/>
<xsl:text>][2] = '</xsl:text>
<xsl:value-of select="status"/>
<xsl:text>';
</xsl:text>
<!--******************-->
<!-- Service request Resolution Type -->
<xsl:text>SRArray[</xsl:text>
<xsl:value-of select="$caseIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srTranIndex"/>
<xsl:text>][3] = '</xsl:text>
<xsl:value-of select="trandate"/>
<xsl:text>';
</xsl:text>
<!--******************-->
<!-- Service request Resolution Description -->
<xsl:text>SRArray[</xsl:text>
<xsl:value-of select="$caseIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srTranIndex"/>
<xsl:text>][4] = '</xsl:text>
<xsl:value-of select="rescode"/>
<xsl:text>';
</xsl:text>
<!--******************-->
<!-- Service request Creation Date -->
<xsl:text>SRArray[</xsl:text>
<xsl:value-of select="$caseIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srTranIndex"/>
<xsl:text>][5] = '</xsl:text>
<xsl:value-of select="restype"/>
<xsl:text>';
</xsl:text>
<!--******************-->
<!-- Service request Last Transaction Date -->
<xsl:text>SRArray[</xsl:text>
<xsl:value-of select="$caseIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srTranIndex"/>
<xsl:text>][6] = '</xsl:text>
<xsl:value-of select="resdesc"/>
<xsl:text>';
</xsl:text>
<!--******************-->
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="Case">
<xsl:variable name="caseIndex" select="position()"/>
<xsl:variable name="CaseCount" select="count(*)"/>
<xsl:for-each select="*">
<xsl:variable name="srIndex" select="position()"/>
<xsl:text>SRArray [</xsl:text>
<xsl:value-of select="$caseIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srIndex"/>
<xsl:text>] = new Array();
</xsl:text>
<xsl:text>
</xsl:text>
<xsl:for-each select="*">
<xsl:variable name="srTranIndex" select="position()"/>
<xsl:text>SRArray [</xsl:text>
<xsl:value-of select="$caseIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srIndex"/>
<xsl:text>][</xsl:text>
<xsl:value-of select="$srTranIndex"/>
<xsl:text>] = new Array();
</xsl:text>
<xsl:text>
</xsl:text>
<xsl:apply-templates
select="/SRSource/Case/ServiceRequest/SRTransaction">
<xsl:with-param name="caseIndex" select="$caseIndex"/>
<xsl:with-param name="srIndex" select="$srIndex"/>
<xsl:with-param name="srTranIndex" select="$srTranIndex"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<!--<xsl:with-param name="caseIndex" select="$caseIndex"/>
<xsl:with-param name="srIndex" select="position()"/>
<xsl:variable name="parentPosition"
select="../position()"/>
<xsl:if test="$parentPosition = $caseIndex">
<xsl:param name="caseIndex"/>
<xsl:param name="srIndex"/>
</xsl:if>
<xsl:text>SRArray [</xsl:text>
<xsl:value-of select="$caseIndex"/>
<xsl:text>]= new Array();
</xsl:text>
-->
2- XML source
<?xml-stylesheet type="text/xsl" href="ArrayLoadTest.xsl"?>
<SRSource>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID1-1-1</srID>
<status>status1-1-1</status>
<trandate>trandate1-1-1</trandate>
<rescode>rescode1-1-1</rescode>
<restype>restype1-1-1</restype>
<resdesc>resdesc1-1-1</resdesc>
</SRTransaction>
<SRTransaction>
<srID>srID1-1-2</srID>
<status>status1-1-2</status>
<trandate>trandate1-1-2</trandate>
<rescode>rescode1-1-2</rescode>
<restype>restype1-1-2</restype>
<resdesc>resdesc1-1-2</resdesc>
</SRTransaction>
<SRTransaction>
<srID>srID1-1-3</srID>
<status>status1-1-3</status>
<trandate>trandate1-1-3</trandate>
<rescode>rescode1-1-3</rescode>
<restype>restype1-1-3</restype>
<resdesc>resdesc1-1-3</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID2-1-1</srID>
<status>status2-1-1</status>
<trandate>trandate2-1-1</trandate>
<rescode>rescode2-1-1</rescode>
<restype>restype2-1-1</restype>
<resdesc>resdesc2-1-1</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID3-1-1</srID>
<status>status3-1-1</status>
<trandate>trandate3-1-1</trandate>
<rescode>rescode3-1-1</rescode>
<restype>restype3-1-1</restype>
<resdesc>resdesc3-1-1</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID4-1-1</srID>
<status>status4-1-1</status>
<trandate>trandate4-1-1</trandate>
<rescode>rescode4-1-1</rescode>
<restype>restype4-1-1</restype>
<resdesc>resdesc4-1-1</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID5-1-1</srID>
<status>status5-1-1</status>
<trandate>trandate5-1-1</trandate>
<rescode>rescode5-1-1</rescode>
<restype>restype5-1-1</restype>
<resdesc>resdesc5-1-1</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID6-1-1</srID>
<status>status6-1-1</status>
<trandate>trandate6-1-1</trandate>
<rescode>rescode6-1-1</rescode>
<restype>restype6-1-1</restype>
<resdesc>resdesc6-1-1</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID7-1-1</srID>
<status>status7-1-1</status>
<trandate>trandate7-1-1</trandate>
<rescode>rescode7-1-1</rescode>
<restype>restype7-1-1</restype>
<resdesc>resdesc7-1-1</resdesc>
</SRTransaction>
</ServiceRequest>
<ServiceRequest>
<SRTransaction>
<srID>srID7-2-1</srID>
<status>status7-2-1</status>
<trandate>trandate7-2-1</trandate>
<rescode>rescode7-2-1</rescode>
<restype>restype7-2-1</restype>
<resdesc>resdesc7-2-1</resdesc>
</SRTransaction>
<SRTransaction>
<srID>srID7-2-2</srID>
<status>status7-2-2</status>
<trandate>trandate7-2-2</trandate>
<rescode>rescode7-2-2</rescode>
<restype>restype7-2-2</restype>
<resdesc>resdesc7-2-2</resdesc>
</SRTransaction>
<SRTransaction>
<srID>srID7-2-3</srID>
<status>status7-2-3</status>
<trandate>trandate7-2-3</trandate>
<rescode>rescode7-2-3</rescode>
<restype>restype7-2-3</restype>
<resdesc>resdesc7-2-3</resdesc>
</SRTransaction>
<SRTransaction>
<srID>srID7-2-4</srID>
<status>status7-2-4</status>
<trandate>trandate7-2-4</trandate>
<rescode>rescode7-2-4</rescode>
<restype>restype7-2-4</restype>
<resdesc>resdesc7-2-4</resdesc>
</SRTransaction>
</ServiceRequest>
<ServiceRequest>
<SRTransaction>
<srID>srID7-3-1</srID>
<status>status7-3-1</status>
<trandate>trandate7-3-1</trandate>
<rescode>rescode7-3-1</rescode>
<restype>restype7-3-1</restype>
<resdesc>resdesc7-3-1</resdesc>
</SRTransaction>
</ServiceRequest>
<ServiceRequest>
<SRTransaction>
<srID>srID7-4-1</srID>
<status>status7-4-1</status>
<trandate>trandate7-4-1</trandate>
<rescode>rescode7-4-1</rescode>
<restype>restype7-4-1</restype>
<resdesc>resdesc7-4-1</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID8-1-1</srID>
<status>status8-1-1</status>
<trandate>trandate8-1-1</trandate>
<rescode>rescode8-1-1</rescode>
<restype>restype8-1-1</restype>
<resdesc>resdesc8-1-1</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID9-1-1</srID>
<status>status9-1-1</status>
<trandate>trandate9-1-1</trandate>
<rescode>rescode9-1-1</rescode>
<restype>restype9-1-1</restype>
<resdesc>resdesc9-1-1</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
<Case>
<ServiceRequest>
<SRTransaction>
<srID>srID10-1-1</srID>
<status>status10-1-1</status>
<trandate>trandate10-1-1</trandate>
<rescode>rescode10-1-1</rescode>
<restype>restype10-1-1</restype>
<resdesc>resdesc10-1-1</resdesc>
</SRTransaction>
</ServiceRequest>
</Case>
</SRSource>
3- result
<html xmlns:fo="http://www.w3.org/1999/XSL/Format">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title><script type="text/javascript" language="JavaScript">
var SRArray = new Array();
SRArray [1] = new Array();
SRArray [2] = new Array();
SRArray [3] = new Array();
SRArray [4] = new Array();
SRArray [5] = new Array();
SRArray [6] = new Array();
SRArray [7] = new Array();
SRArray [8] = new Array();
SRArray [9] = new Array();
SRArray[10] = new Array();
SRArray [1][1] = new Array();
SRArray [1][1][1] = new Array();
SRArray[1][1][1][1] = 'srID1-1-1';
SRArray[1][1][1][2] = 'status1-1-1';
SRArray[1][1][1][3] = 'trandate1-1-1';
SRArray[1][1][1][4] = 'rescode1-1-1';
SRArray[1][1][1][5] = 'restype1-1-1';
SRArray[1][1][1][6] = 'resdesc1-1-1';
SRArray [1][1][2] = new Array();
SRArray[1][1][2][1] = 'srID1-1-2';
SRArray[1][1][2][2] = 'status1-1-2';
SRArray[1][1][2][3] = 'trandate1-1-2';
SRArray[1][1][2][4] = 'rescode1-1-2';
SRArray[1][1][2][5] = 'restype1-1-2';
SRArray[1][1][2][6] = 'resdesc1-1-2';
SRArray [1][1][3] = new Array();
SRArray[1][1][3][1] = 'srID1-1-3';
SRArray[1][1][3][2] = 'status1-1-3';
SRArray[1][1][3][3] = 'trandate1-1-3';
SRArray[1][1][3][4] = 'rescode1-1-3';
SRArray[1][1][3][5] = 'restype1-1-3';
SRArray[1][1][3][6] = 'resdesc1-1-3';
SRArray [2][1] = new Array();
SRArray [2][1][1] = new Array();
SRArray[2][1][1][1] = 'srID2-1-1';
SRArray[2][1][1][2] = 'status2-1-1';
SRArray[2][1][1][3] = 'trandate2-1-1';
SRArray[2][1][1][4] = 'rescode2-1-1';
SRArray[2][1][1][5] = 'restype2-1-1';
SRArray[2][1][1][6] = 'resdesc2-1-1';
SRArray [3][1] = new Array();
SRArray [3][1][1] = new Array();
SRArray[3][1][1][1] = 'srID3-1-1';
SRArray[3][1][1][2] = 'status3-1-1';
SRArray[3][1][1][3] = 'trandate3-1-1';
SRArray[3][1][1][4] = 'rescode3-1-1';
SRArray[3][1][1][5] = 'restype3-1-1';
SRArray[3][1][1][6] = 'resdesc3-1-1';
SRArray [4][1] = new Array();
SRArray [4][1][1] = new Array();
SRArray[4][1][1][1] = 'srID4-1-1';
SRArray[4][1][1][2] = 'status4-1-1';
SRArray[4][1][1][3] = 'trandate4-1-1';
SRArray[4][1][1][4] = 'rescode4-1-1';
SRArray[4][1][1][5] = 'restype4-1-1';
SRArray[4][1][1][6] = 'resdesc4-1-1';
SRArray [5][1] = new Array();
SRArray [5][1][1] = new Array();
SRArray[5][1][1][1] = 'srID5-1-1';
SRArray[5][1][1][2] = 'status5-1-1';
SRArray[5][1][1][3] = 'trandate5-1-1';
SRArray[5][1][1][4] = 'rescode5-1-1';
SRArray[5][1][1][5] = 'restype5-1-1';
SRArray[5][1][1][6] = 'resdesc5-1-1';
SRArray [6][1] = new Array();
SRArray [6][1][1] = new Array();
SRArray[6][1][1][1] = 'srID6-1-1';
SRArray[6][1][1][2] = 'status6-1-1';
SRArray[6][1][1][3] = 'trandate6-1-1';
SRArray[6][1][1][4] = 'rescode6-1-1';
SRArray[6][1][1][5] = 'restype6-1-1';
SRArray[6][1][1][6] = 'resdesc6-1-1';
SRArray [7][1] = new Array();
SRArray [7][1][1] = new Array();
SRArray[7][1][1][1] = 'srID7-1-1';
SRArray[7][1][1][2] = 'status7-1-1';
SRArray[7][1][1][3] = 'trandate7-1-1';
SRArray[7][1][1][4] = 'rescode7-1-1';
SRArray[7][1][1][5] = 'restype7-1-1';
SRArray[7][1][1][6] = 'resdesc7-1-1';
SRArray [7][2] = new Array();
SRArray [7][2][1] = new Array();
SRArray[7][2][1][1] = 'srID7-2-1';
SRArray[7][2][1][2] = 'status7-2-1';
SRArray[7][2][1][3] = 'trandate7-2-1';
SRArray[7][2][1][4] = 'rescode7-2-1';
SRArray[7][2][1][5] = 'restype7-2-1';
SRArray[7][2][1][6] = 'resdesc7-2-1';
SRArray [7][2][2] = new Array();
SRArray[7][2][2][1] = 'srID7-2-2';
SRArray[7][2][2][2] = 'status7-2-2';
SRArray[7][2][2][3] = 'trandate7-2-2';
SRArray[7][2][2][4] = 'rescode7-2-2';
SRArray[7][2][2][5] = 'restype7-2-2';
SRArray[7][2][2][6] = 'resdesc7-2-2';
SRArray [7][2][3] = new Array();
SRArray[7][2][3][1] = 'srID7-2-3';
SRArray[7][2][3][2] = 'status7-2-3';
SRArray[7][2][3][3] = 'trandate7-2-3';
SRArray[7][2][3][4] = 'rescode7-2-3';
SRArray[7][2][3][5] = 'restype7-2-3';
SRArray[7][2][3][6] = 'resdesc7-2-3';
SRArray [7][2][4] = new Array();
SRArray[7][2][4][1] = 'srID7-2-4';
SRArray[7][2][4][2] = 'status7-2-4';
SRArray[7][2][4][3] = 'trandate7-2-4';
SRArray[7][2][4][4] = 'rescode7-2-4';
SRArray[7][2][4][5] = 'restype7-2-4';
SRArray[7][2][4][6] = 'resdesc7-2-4';
SRArray [7][3] = new Array();
SRArray [7][3][1] = new Array();
SRArray[7][3][1][1] = 'srID7-3-1';
SRArray[7][3][1][2] = 'status7-3-1';
SRArray[7][3][1][3] = 'trandate7-3-1';
SRArray[7][3][1][4] = 'rescode7-3-1';
SRArray[7][3][1][5] = 'restype7-3-1';
SRArray[7][3][1][6] = 'resdesc7-3-1';
SRArray [7][4] = new Array();
SRArray [7][4][1] = new Array();
SRArray[7][4][1][1] = 'srID7-4-1';
SRArray[7][4][1][2] = 'status7-4-1';
SRArray[7][4][1][3] = 'trandate7-4-1';
SRArray[7][4][1][4] = 'rescode7-4-1';
SRArray[7][4][1][5] = 'restype7-4-1';
SRArray[7][4][1][6] = 'resdesc7-4-1';
SRArray [8][1] = new Array();
SRArray [8][1][1] = new Array();
SRArray[8][1][1][1] = 'srID8-1-1';
SRArray[8][1][1][2] = 'status8-1-1';
SRArray[8][1][1][3] = 'trandate8-1-1';
SRArray[8][1][1][4] = 'rescode8-1-1';
SRArray[8][1][1][5] = 'restype8-1-1';
SRArray[8][1][1][6] = 'resdesc8-1-1';
SRArray [9][1] = new Array();
SRArray [9][1][1] = new Array();
SRArray[9][1][1][1] = 'srID9-1-1';
SRArray[9][1][1][2] = 'status9-1-1';
SRArray[9][1][1][3] = 'trandate9-1-1';
SRArray[9][1][1][4] = 'rescode9-1-1';
SRArray[9][1][1][5] = 'restype9-1-1';
SRArray[9][1][1][6] = 'resdesc9-1-1';
SRArray [10][1] = new Array();
SRArray [10][1][1] = new Array();
SRArray[10][1][1][1] = 'srID10-1-1';
SRArray[10][1][1][2] = 'status10-1-1';
SRArray[10][1][1][3] = 'trandate10-1-1';
SRArray[10][1][1][4] = 'rescode10-1-1';
SRArray[10][1][1][5] = 'restype10-1-1';
SRArray[10][1][1][6] = 'resdesc10-1-1';
alert(fdfa);
</script></head>
<body></body>
</html>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list