xsl-list
[Top] [All Lists]

RE: [xsl] FW: XSL processes XML incorrectly when uneven number of values returned in array elements

2006-03-09 06:34:13
Apologies...

I just took typed out an excerpt from the XML by hand.
The XML I'm using is well formed, the XSL is fine as well, I just did
not want to send everything...

But if you want, the full xml and xsl are as follows.
If you apply the XSL you will see that the first table column starts
from line 3 whilst the actual occurrence of the value is the first [0]
in the XML for optionList1/option...


Xml starts ----

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl"
href="transactions.xsl"?><integration-wrapper><integrationPosition>befor
e</integrationPosition><integrationStep>details</integrationStep><userSe
ssion><userId>ADMIN</userId><fullName>
Administrator</fullName><superUser>true</superUser><serviceMode>Front
Office</serviceMode><logonTime>2006-02-20T17:10:56:850</logonTime><membe
rship><group>SysDoc-Administrator</group><group>ADMIN</group></membershi
p></userSession><enquiry
name="12SAG06051171127"><parent>03SAG06019130030</parent><parent-descrip
tion>Finance
Staff</parent-description><visit-no>20060220/018</visit-no><enquiry-no>1
00306</enquiry-no><enquiry-type>CSO</enquiry-type><customer>11SAG0602512
5815</customer><customer-data><title>Mr</title><forename>Shaun</forename
<initials/><surname>Thomson</surname><dangerous-person>
</dangerous-person><paon>21</paon><saon>7503055007087</saon><street-name
Jump
Street</street-name><locality>13</locality><town>Benoni</town><county>Ga
uteng</county><postcode>1234</postcode><home-telephone>0112565338</home-
telephone><business-address>No</business-address><fax/><email>shaun(_at_)here
.com</email><customer-last-updated>20060201103723965</customer-last-upda
ted></customer-data><service>07SAG06051165343</service><service-data><de
scription>Debtor Information</description><detail>Debtor enquiry
service</detail><pre-requisites/><timescale>5</timescale><timescale-unit
Minutes</timescale-unit><procedure/><service-provided-by>CSO</service-p
rovided-by><service-owner>03SAG06019130030</service-owner><service-owner
-description>Finance
Staff</service-owner-description><service-last-updated>20060220165931883
</service-last-updated></service-data><status>Assigned</status><event>fa
lse</event><priority><level>normal</level><reason/></priority><step>serv
ices</step><held-by>ADMIN</held-by><items-received/><comments/><enquiry-
history enquirystatus="Logged"
enquirydatetime="20060220171125068"/><enquiry-history
enquirystatus="Assigned" enquirydatetime="20060220171125068"/><searchKey
key="ACCOUNTNUMBERTEXT1701997166"/><searchKey key="STANDADDRESSTEXT21
BORON LANE"/><searchKey
key="STANDNUMBERTEXTT51026000021250000000000000"/><searchKey
key="IDNUMBERTEXT"/><searchKey key="OLDACCOUNTNUMBERTEXT"/><searchKey
key="SUNDRYREVIEWKEYTEXT"/><created>20060220171126318</created><created-
by>ADMIN</created-by><last-updated>20060220171127678</last-updated><last
-updated-by>ADMIN</last-updated-by><last-updated-fullname>
Administrator</last-updated-fullname><date-raised>20060220171127678</dat
e-raised><date-due>20060220171627678</date-due><process-generation>1</pr
ocess-generation><source>Front
Office</source><image-details/><officer-involved>
Administrator</officer-involved><enquiry-data><ExempOtherText
description="Exemp Other"
type="text">0.00</ExempOtherText><BuildingValueText
description="Building Value"
type="text">0</BuildingValueText><AccountNumberText description="Account
Number" type="text">1701997166</AccountNumberText><TermDateText
description="Term Date" type="text"/><DebtorAddress1Text
description="Debtor Address 1" type="text">2125 BORON
LANE</DebtorAddress1Text><StandAddressText description="Stand Address"
type="text">21 BORON LANE</StandAddressText><StandNumberText
description="Stand Number"
type="text">T51026000021250000000000000</StandNumberText><WardText
description="Ward " type="text">1</WardText><OwnerAddress3Text
description="Owner Address 3" type="text"/><DebtorNameText
description="Debtor Name" type="text">MOYAKE M D AND M A
.</DebtorNameText><ExempGroundText description="Exemp Ground"
type="text">0.00</ExempGroundText><OwnerPostCodeText description="Owner
Post Code" type="text">1665</OwnerPostCodeText><ImproveText
description="Improve" type="text">115000.00</ImproveText><ExtArrText
description="Ext Arr" type="text">0</ExtArrText><ClearanceCertPrintText
description="Clearance Cert Print" type="text"/><OwnerIDNumberText
description="Owner ID Number"
type="text">7810180363082</OwnerIDNumberText><OtherText
description="Other" type="text">0.00</OtherText><DebtorAccountNumberText
description="Debtor Account Number"
type="text">1701997166</DebtorAccountNumberText><GroundText
description="Ground" type="text">17000.000</GroundText><FloorAreaText
description="Floor Area" type="text">0</FloorAreaText><optionConstant
description="option" type="constant">1</optionConstant><ApplyDateText
description="Apply Date" type="text"/><AgriSizeText description="Agri
Size" type="text">0</AgriSizeText><OriginalDateText
description="Original Date"
type="text">0</OriginalDateText><ExempAgricultureText description="Exemp
Agriculture" type="text">0.00</ExempAgricultureText><OwnerAddress1Text
description="Owner Address 1" type="text">2125 BORON
LANE</OwnerAddress1Text><IDNumberText description="ID Number"
type="text"/><RouteNumberText description="Route Number"
type="text">2125</RouteNumberText><OwnerNameText description="Owner
Name" type="text">MOYAKE M D AND M A .</OwnerNameText><TermText
description="Term Date" type="text">0</TermText><DateFromText
description="Date From"
type="text">0</DateFromText><OldAccountNumberText description="Old
Account Number" type="text"/><ZoneCodeText description="Zone Code"
type="text">RES1</ZoneCodeText><DepositsText description="Deposits"
type="text">1</DepositsText><LandUseCodeText description="Land Use Code"
type="text">219</LandUseCodeText><ClearanceCostPrintText
description="Clearance Cost Print"
type="text">0</ClearanceCostPrintText><OwnerAddress2Text
description="Owner Address 2" type="text">CLAYVILLE X
26</OwnerAddress2Text><DebtorPostCodeText description="Debtor Post Code"
type="text">1665</DebtorPostCodeText><ComplexNumberText
description="Complex Number" type="text"/><OptionsConstant
description="Options"
type="constant">Services</OptionsConstant><SizeText description="Size"
type="text">227</SizeText><BussSizeText description="Buss Size"
type="text">0</BussSizeText><AgricultureText description="Agriculture"
type="text">0.00</AgricultureText><DescriptionText
description="Description" type="text">STAND
00002125</DescriptionText><actionConstant description="action"
type="constant">1</actionConstant><DebtorIDNumberText
description="Debtor ID Number"
type="text">7810180363082</DebtorIDNumberText><DebtorAddress2Text
description="Debtor Address 2" type="text">CLAYVILLE X
26</DebtorAddress2Text><DateToText description="Date To"
type="text">0</DateToText><DebtorAddress3Text description="Debtor
Address 3" type="text"/><NotesText description="Notes"
type="text">3</NotesText><OwnerAccountNumberText description="Owner
Account Number"
type="text">1701997166</OwnerAccountNumberText><BookNumberText
description="Book Number"
type="text">N10251</BookNumberText><SundryReviewKeyText
description="Sundry Review Key" type="text"/><ExempImproveText
description="Exemp Improve"
type="text">0.00</ExempImproveText><free-xml><TranOptionList1><option/><
option>20051125</option><option>20051128</option><option>20051223</optio
n><option>20051223</option><option>20051223</option><option>20051223</op
tion><option>20051223</option></TranOptionList1><TranOptionList2><option
BALANCE B/FWD</option><option>000018 RECEIPT</option><option>WATER
CONS. RESIDENTIAL</option><option>SEWER CONS.
RESIDENTIAL</option><option>ASS RATES RESIDENTIAL
DOMESTIC</option><option>ASSESSMENT RATES
DISCOUNT</option><option>REFUSE: DOMESTIC 1 X PER
WEEK</option><option>TOTAL</option><option/><option>CASH
UNTIL-</option></TranOptionList2><TranOptionList3><option/><option>89009
13301</option><option>33200126</option><option>33200126</option><option>
0000000000</option><option>0000000000</option><option>.</option><option/
<option>CURRENT</option><option>20060118</option></TranOptionList3><Tra
nOptionList4><option/><option/><option>WA0017</option><option>SE0017</op
tion><option>VA0019</option><option>VA0019</option><option>BR0001</optio
n><option/><option>BAL:</option></TranOptionList4><TranOptionList5><opti
on>237.82</option><option>0.00</option><option>0.00</option><option>0.00
</option><option>146.77</option><option>0.00</option><option>38.57</opti
on><option>264.85</option><option>264.85</option></TranOptionList5><Tran
OptionList6><option>0.00</option><option>105.00</option><option>0.00</op
tion><option>0.00</option><option>0.00</option><option>58.71</option></T
ranOptionList6><TranOptionList7><option>0.00</option><option>0.00</optio
n><option>0.00</option><option>0.00</option><option>0.00</option><option
0.00</option><option>5.40</option></TranOptionList7></free-xml></enquir
y-data></enquiry><integrationErrors/></integration-wrapper>

Xml end -------------

XSL starts --------

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
        <xsl:template match="enquiry">
                <input xmlns:fo="http://www.w3.org/1999/XSL/Format";
type="hidden" name="STEP" value="{step}"/>
                <table class="footer">
                        <tr>
                                <td>
                                        <b>Enquiry No:</b>
                                        <xsl:value-of
select="enquiry-no"/>
                                </td>
                                <td align="right">
                                        <b>Status:</b>
                                        <xsl:value-of select="status"/>
/ <xsl:value-of select="step"/>
                                </td>
                        </tr>
                </table>

<script src="javascript/popcalendarCRM.js.jsp" type="text/javascript">
<xsl:comment>/*Comment*/</xsl:comment>
</script>

                <script language="javascript">
function strtrim() { return
this.replace(/^\s+/,&apos;&apos;).replace(/\s+$/,&apos;&apos;); }
String.prototype.trim = strtrim;
function enquiryKey()
{
        <xsl:choose>
                                <xsl:when test="@name">var key
=&apos;<xsl:value-of select="@name"/>&apos;; </xsl:when>
                                <xsl:otherwise>var key
=&apos;&apos;;</xsl:otherwise>
                        </xsl:choose>
        return key;
}

function updateEnquiry()
{
        if(checkStatus()){
                submitActionForm(&apos;NEXT&apos;);
        }
}

function onload()
{
                doneOnload=true;
}
</script>
                <xsl:if test="../messages">
                        <table
xmlns:fo="http://www.w3.org/1999/XSL/Format"; style="border-bottom:solid
1px" border="0" class="tabData">
                                <xsl:for-each
select="../messages/message">
                                        <tr>
                                                <td>
                                                        <xsl:value-of
select="severity"/>
                                                </td>
                                                <td>
                                                        <xsl:value-of
select="messageText"/>
                                                </td>
                                        </tr>
                                </xsl:for-each>
                        </table>
                </xsl:if>
                
                <!-- CHANGE HERE -->
                <table class="details">
                        <tr>
                                <td>
                                        <xsl:apply-templates
select="enquiry-data"/>
                                </td>
                        </tr>
                </table>
                <!-- =========== -->
                
                <input xmlns:fo="http://www.w3.org/1999/XSL/Format";
type="hidden" name="RECEIVED"/>
                <input xmlns:fo="http://www.w3.org/1999/XSL/Format";
type="hidden" name="COMMENTS"/>
                <input xmlns:fo="http://www.w3.org/1999/XSL/Format";
type="hidden" name="LAST_UPDATED" value="{last-updated}"/>
                <input xmlns:fo="http://www.w3.org/1999/XSL/Format";
id="status" name="status" type="radio" value="" checked=""
style="display:none"/>
                <input xmlns:fo="http://www.w3.org/1999/XSL/Format";
id="status" name="status" type="hidden" value=""/>
        </xsl:template>

        <!-- CHANGE HERE -->
        <xsl:template match="enquiry-data">
                <table id="ButtonTable" tabIndex="1" cellpadding="5"
cellspacing="0">
                        
<tr>
<td>
<input type="hidden" name="X.OptionsConstant" id="X_OptionsConstant"/>
</td>
<td>
<input type="button" value="DETAILS"
onclick="document.forms[0].elements['X_OptionsConstant'].value='AccountD
etails';updateEnquiry();"/>
</td>
<td>
<input type="button" value="TRANSACTIONS"
onclick="document.forms[0].elements['X_OptionsConstant'].value='Transact
ions';updateEnquiry();"/>
</td>
<td>
<input type="button" value="SERVICES"
onclick="document.forms[0].elements['X_OptionsConstant'].value='Services
';updateEnquiry();"/>
</td>
<td>
<input type="button" value="OWNER_TENANT"
onclick="document.forms[0].elements['X_OptionsConstant'].value='Owner_Te
nant';updateEnquiry();"/>
</td>
<td>
<input type="button" value="METERS"
onclick="document.forms[0].elements['X_OptionsConstant'].value='Meters';
updateEnquiry();"/>
</td>
<td>
<input type="button" value="BALANCES"
onclick="document.forms[0].elements['X_OptionsConstant'].value='Balances
';updateEnquiry();"/>
</td>
<td>
<input type="button" value="SUMMARY"
onclick="document.forms[0].elements['X_OptionsConstant'].value='Summary'
;updateEnquiry();"/>
</td>
<td>
<input type="button" value="CREDITS"
onclick="document.forms[0].elements['X_OptionsConstant'].value='Credits'
;updateEnquiry();"/>
</td>
<td>
<input type="button" value="PRINT" onclick="window.print()"/>
</td>
<td>
<input type="button" value="QUIT"
onclick="document.forms[0].elements['X_OptionsConstant'].value='Quit';up
dateEnquiry();"/>
</td>
</tr>
</table>
<table id="inputTable" tabIndex="1" cellpadding="5" cellspacing="0">

                        <tr><td> <b> Stand Info </b></td></tr>
                        <tr>
                                <td> Owner Account Number: </td>
                                <td> <input type="text"
name="X.OwnerAccountNumberText" id="X_OwnerAccountNumberText"
value="{OwnerAccountNumberText}"/>
                                </td>
                                <td> Owner Name: </td>
                                <td> <input type="text"
name="X.OwnerNameText" id="X_OwnerNameText" value="{OwnerNameText}"/>
                                </td>
                                
                        </tr>
                        
                        
                        
                        
                        
                        
                        
                        <tr>
                                <td> Stand Number: </td> 
                                <td> <input type="text"
name="X.StandNumberText" id="X_StandNumberText"
value="{StandNumberText}"/>
                                </td>
                                <td> Stand Address: </td>
                                <td> <input type="text"
name="X.StandAddressText" id="X_StandAddressText"
value="{StandAddressText}"/>
                                </td>   
                                                
                        </tr>

<tr>

                                <td> Transaction Date (YYYYMM): </td> 
        <td> 
        
        <xsl:variable name="tranMonthVar">
        <xsl:choose>
                <xsl:when
test="not(//enquiry-data/TranMonthText)">200601</xsl:when>
                <xsl:otherwise><xsl:value-of
select="//enquiry-data/TranMonthText"/></xsl:otherwise>
        </xsl:choose>
        </xsl:variable>
        <input type="text" name="X.TranMonthText" id="X_TranMonthText"
value="{$tranMonthVar}"/>
        
        </td>

<td>
<input type="button" value="GET TRANSACTIONS"
onclick="document.forms[0].elements['X_OptionsConstant'].value='Transact
ions';updateEnquiry();"/>
</td>
</tr>
                        
                        


                </table>

<table id="ResultTable" tabIndex="1" cellpadding="5" cellspacing="0">



                        <tr>

<td width="150"> <b> TRANS DATE </b></td>

                        <td width="350"> <b> DESCRIPTION </b></td>

                        <td width="80"> <b> REFERENCE </b></td>

                        <td width="80"> <b> TARIFF </b></td>

                <td width="80"> <b> DEBIT </b></td>

                        <td width="80"> <b> CREDIT </b></td>

<td width="80"> <b> VAT </b></td>


</tr>



                

<tr>

<td>    
                
<xsl:for-each select="//enquiry-data/free-xml/TranOptionList1/*">
<a href="javascript:alert('pressed {(_at_)value}');"> <xsl:value-of
select="."/></a><br/>
</xsl:for-each>
</td>

<td>                    
<xsl:for-each select="//enquiry-data/free-xml/TranOptionList2/*">
<a href="javascript:alert('pressed {(_at_)value}');"> <xsl:value-of
select="."/></a><br/>
</xsl:for-each>
</td>

<td>                    
<xsl:for-each select="//enquiry-data/free-xml/TranOptionList3/*">
<a href="javascript:alert('pressed {(_at_)value}');"> <xsl:value-of
select="."/></a><br/>
</xsl:for-each>
</td>

<td>                    
<xsl:for-each select="//enquiry-data/free-xml/TranOptionList4/*">
<a href="javascript:alert('pressed {(_at_)value}');"><xsl:value-of
select="."/></a><br/>
</xsl:for-each>
</td>


<td>
<xsl:for-each select="//enquiry-data/free-xml/TranOptionList5/*">
<xsl:variable name="DescVar">
<xsl:variable name="xmlNode" select="."/>
<xsl:choose>
<xsl:when test="starts-with($xmlNode ,'+')"><xsl:value-of
select="substring-after($xmlNode,'+')"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$xmlNode"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="javascript:alert('pressed {(_at_)value}');"> <xsl:value-of
select="format-number($DescVar,'####.00')"/></a><br/>
</xsl:for-each>
</td>


<td>
<xsl:for-each select="//enquiry-data/free-xml/TranOptionList6/*">
<xsl:variable name="DescVar">
<xsl:variable name="xmlNode" select="."/>
<xsl:choose>
<xsl:when test="starts-with($xmlNode ,'+')"><xsl:value-of
select="substring-after($xmlNode,'+')"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$xmlNode"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="javascript:alert('pressed {(_at_)value}');"> <xsl:value-of
select="format-number($DescVar,'####.00')"/></a><br/>
</xsl:for-each>
</td>

<td>
<xsl:for-each select="//enquiry-data/free-xml/TranOptionList7/*">
<xsl:variable name="DescVar">
<xsl:variable name="xmlNode" select="."/>
<xsl:choose>
<xsl:when test="starts-with($xmlNode ,'+')"><xsl:value-of
select="substring-after($xmlNode,'+')"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$xmlNode"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a href="javascript:alert('pressed {(_at_)value}');"> <xsl:value-of
select="format-number($DescVar,'####.00')"/></a><br/>
</xsl:for-each>
</td>

</tr>   
                        
</table>                
                        
                        






        </xsl:template>
        <!-- ========== -->
        
        
</xsl:stylesheet>

XSL ends -----------
 

-----Original Message-----
From: cknell(_at_)onebox(_dot_)com [mailto:cknell(_at_)onebox(_dot_)com] 
Sent: 09 March 2006 03:19 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] FW: XSL processes XML incorrectly when uneven number
of values returned in array elements

Tsk, tsk, tsk. 

1) The data document isn't well-formed.

<optionList1>
 <option>1</option>
 <option>2</option>
</List1>

Note the opening tag doesn't match the closing tag, therefor this isn't
XML.
Now, correcting this, I moved on to the XSLT and found that what it's
trying to output isn't HTML:

<xsl:for-each select="//enquiry-data/free-xml/optionList1/*">
<xsl:value-of select="."/></a><br/>
</xsl:for-each>

Note the closing </a> doesn't have a matching opener (<a>).

Now how about an example output of what you want to get from the
transformation, or at least, tell us whether each <optionListx> should
produce a row in the output or should it produce a column in which case
the <option> elements with matching positions relative to it's siblings
make up the successive <td> elements in the output. (This last sentence
is why I recommend example output rather than descriptions of the
desired output.)

And here's another piece of advice. If you have any control over the XML
format, immediately kill the idea that each <optionListx> element should
have a unique name. If you need to differentiate them, use an attribute.
So ...

<optionList1> becomes <optionList id="1"> <optionList2> becomes
<optionList id="2"> <optionList3> becomes <optionList id="3">

This will make writing and maintaining a stylesheet much easier.

--
Charles Knell
cknell(_at_)onebox(_dot_)com - email


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--