xsl-list
[Top] [All Lists]

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

2012-08-16 05:22:51

I've not yet tried this group-based approach, or the Tree Walking approach from 
Dave's FAQ....

Before I start looking at those approaches, and before I'd received these 
replies from you, I'd been trying to do the task by manipulating the axis to be 
used for applying the next template.

I have something like :

<xsl:variable name="axis" 
select="following-sibling::element()[preceding-sibling::element()[column[1] = 
'']]" />
<xsl:apply-templates select="$axis" mode="col-1" />

What I mean by this is :
following-sibling::element() - all subsequent "row" elements in the document.
[preceding-sibling::element()[column[1] = '']]"  - but only those which have no 
column[1] text in elements preceding them.

I've tried this using element(), node() and *, and = and !=, but I don't get 
the restricted axis I want.

Should I expect this approach to work ?
If so, can anyone advise what I might need to change.
If not, why not ?  


Regards,
Richard.

PS, XSTL-2, via Saxon 9 HE.


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 17:20
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Process following siblings that have no text into children.

Richard,

Because I like to test stuff using Kernow [1] so much, I came up with this 
little template for <sheet>:

<xsl:template match="sheet">
  <result name="{@name}">
    <xsl:for-each-group select="row" group-starting-with="row[column[1][. != 
'']]" >
      <item row="{@row}" name="{column[1]}">
        <xsl:for-each select="current-group()">
          <sub-item value="{column[3]}"/>
        </xsl:for-each>
      </item>
    </xsl:for-each-group>
  </result>
</xsl:template>

It requires XSLT2, but who would like to do without it?

BTW, your XML example was missing the closing </item> elements.

- Michael

[1]: http://kernowforsaxon.sourceforge.net

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