xsl-list
[Top] [All Lists]

Re: [xsl] streaming XSLT creating a header from a first record

2018-05-15 10:26:10
Yeah, that just did it,
it also seems pretty flexible regarding which row exactly I want to put in the 
header
really cool, bit frustrating it appeared to be so simple in the end
thanks a lot for your help

Best regards, 

Geert Bormans 

-------------------------------------------------------------- 
Markup UK - a conference about XML and other mark-up languages 
London, June 9–10 2018 
Programme now available at [ http://markupuk.org/speakers.xhtml | 
http://markupuk.org/speakers.xhtml ] 
Register at [ http://markupuk.org/registration.xhtml | 
http://markupuk.org/registration.xhtml ]

----- Oorspronkelijk bericht -----
Van: "Abel Braaksma, (Exselt) abel(_at_)exselt(_dot_)net" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Aan: "xsl-list" <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Verzonden: Dinsdag 15 mei 2018 16:54:19
Onderwerp: Re: [xsl] streaming XSLT creating a header from a first record

On 15.05.2018 15:18, Geert Bormans geert(_at_)gbormans(_dot_)telenet(_dot_)be 
wrote:
still trying to get my head around this and facing obstacles,
most likely by lack of understanding... however

example in

<table>
     <row id="row1" attr1="A" attr2="AA"/>
     <row id="row2"  attr1="C" attr2="CC"/>
     <row id="row3"  attr1="D" attr2="DD"/>
</table>

example out

<document>
     <header>
         <!-- process first row here -->
         <id>row1</id>
         <attr1>A</attr1>
         <attr2>AA</attr2>
     </header>
     <content>
         <!-- process all including first row here -->
         <row id="row1" attr1="A" attr2="AA"/>
         <row id="row2" attr1="C" attr2="CC"/>
         <row id="row3" attr1="D" attr2="DD"/>
     </content>
</document>


Using the accumulator or the xsl:iterate approach allows me to process the 
header row twice
but I can't seem to figure out to create the header and then continue the 
iteration in a different construct
it seems I need the header always before the iterator has started

That seems like a job for xsl:fork

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
        xmlns:xs="http://www.w3.org/2001/XMLSchema";
        xmlns:math="http://www.w3.org/2005/xpath-functions/math";
        exclude-result-prefixes="xs math"
        version="3.0">
        
        <xsl:mode streamable="yes" on-no-match="shallow-copy"/>
        
        <xsl:mode name="header" streamable="yes"/>

        <xsl:output indent="yes"/>
        
        <xsl:template match="table">
                <document>
                        <xsl:fork>
                                <xsl:sequence>
                                        <header>
                                                <xsl:apply-templates 
select="row[1]/@*" mode="header"/>
                                        </header>
                                </xsl:sequence>
                                <xsl:sequence>
                                        <content>
                                                <xsl:apply-templates 
select="row"/>
                                        </content>
                                </xsl:sequence>
                        </xsl:fork>
                </document>
        </xsl:template>
        
        <xsl:template match="row/@*" mode="header" expand-text="yes">
                <xsl:element name="{name()}">{.}</xsl:element>
        </xsl:template>
        
</xsl:stylesheet>
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>