xsl-list
[Top] [All Lists]

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

2012-08-15 11:26:59

Michael,
Sorry, yes I'm using Xsl 2 (Saxon 9 HE).

So I should look at groups then ?
Presumably I set up a group containing the set of "row" elements I want to use ?


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(_dot_)kerry(_at_)atos(_dot_)net
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.

________________________________________
From: Michael Müller-Hillebrand [mmh(_at_)docufy(_dot_)de]
Sent: 15 August 2012 16:23
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Process following siblings that have no text into children.

Hi Richard,

If you can use XSLT 2 it would be a nice use case for xsl:for-each-group... if 
you can't it would be something along what is described in Dave Pawsons FAQ as 
"Tree walking"…

It is always helpful to tell what level of XSLT you can use.

- Michael

Am 15.08.2012 um 16:54 schrieb Kerry, Richard:

... 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.





--~------------------------------------------------------------------
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>
--~--