[xsl] Process following siblings that have no text into children.

Subject: [xsl] Process following siblings that have no text into children.
From: "Kerry, Richard" <richard.kerry@xxxxxxxx>
Date: Wed, 15 Aug 2012 14:54:59 +0000
... this is what I really needed to ask in my query from yesterday ...

I have Xml corresponding to part of a spreadsheet, like this :

<sheet name="sheet-1" >
<row row="6">
<column column="1" cell="A6">Reference Present</column>
<column column="2" cell="B6">1,2</column>
<column column="3" cell="C6">1=missing</column>
</row>

<row row="7">
<column column="1" cell="A7"/>
<column column="2" cell="B7"/>
<column column="3" cell="C7">2=present</column>
</row>

<row row="8">
<column column="1" cell="A8">Reference Standard</column>
<column column="2" cell="B8">0-11</column>
<column column="3" cell="C8">0=missing</column>
</row>

<row row="9">
<column column="1" cell="A9"/>
<column column="2" cell="B9"/>
<column column="3" cell="C9">1=525</column>
</row>

<row row="10">
<column column="1" cell="A10"/>
<column column="2" cell="B10"/>
<column column="3" cell="C10">2=625</column>
</row>
</sheet>

What I want to do is to make all the elements that have no text children of
the most recent one which does have text (as well as getting its own column[3]
put into a child).

The result I want is as follows:

<result name="sheet-1" >
<item row="6" name="Reference Present" >
    <sub-item value="1=missing" />
    <sub-item value="2=present" />
<item row="8" name="Reference Standard" >
    <sub-item value="0=missing" />
    <sub-item value="1=525" />
    <sub-item value="2=625" />
</result>

The text from cells C6 and C7 have been used for the sub-item elements which
have been created as children of the item corresponding to row 6 (and A6)
and that from cells C8, C9 and C10 have been used for the sub-item elements
which have been created as children of the item corresponding to row 8 (and
A8).

At the moment I've got the following template in my stylesheet :

<xsl:template match="row[column[1] != '']">
<test-1 row="{@row}" value="{column[3]}" >
    <xsl:variable name="axis" select="following-sibling::element()" />
    <xsl:apply-templates select="$axis" mode="col-1"></xsl:apply-templates>
</test-1>
</xsl:template>

(I have another template to catch "row" with no text in column 1, and one for
"row" with mode=col-1. )

This matches every "row" which does have text in column[1].
It then applies the mode=col-1 template on every following-sibling.

However, that of course runs to the end of the document.  I only actually want
it to run up to, but not including, the next "row" with non-null text.

Please can someone advise what the best way of achieving this would be ?
Do I need just to do a search along $axis for the first non-null text, save
the position in a variable, then use that to select the length of a
subsequence of $axis ?
Or is there a neater way of doing the job ?  Can I get the sequence up to the
next following sibling with non-null text in a single call ?


Puzzledly,
Richard.





Richard Kerry
BNCS Engineer
T: +44 (0)20 82259063
M: +44 (0)7812 325518
Room EBX 301, BBC Television Centre, Wood Lane, London, W12 7RJ
richard.kerry@xxxxxxxx
uk.atos.net

This e-mail and the documents attached are confidential and intended solely
for the addressee; it may also be privileged. If you receive this e-mail in
error, please notify the sender immediately and destroy it. As its integrity
cannot be secured on the Internet, the Atos group liability cannot be
triggered for the message content. Although the sender endeavours to maintain
a computer virus-free network, the sender does not warrant that this
transmission is virus-free and will not be liable for any damages resulting
from any virus transmitted.

Current Thread