xsl-list
[Top] [All Lists]

[xsl] Accumulator use

2016-02-29 05:57:05



        
                
                        
                                
                                        
                                                
                                                        
                                                                
                                                                        
                                                                                
(Sorry for bad formatting, regular email client not working)
                                                                        
                                                                                
 
                                                                        I try to
cache values who are in external files referenced from my source
file :source.xml
                                                                        
------------
                                                                        
<root><input href="1.xml"/><input
href="2.xml"/>...</root>
                                                                        
                                                                                
 
                                                                        n.xml
                                                                        ------
                                                                        <root
type="typeN">...</root>
                                                                        
                                                                                
 
                                                                        I want 
to
create a map(xs:anyUri, xs:string), where key is the external
file URI, and value is always /*/@type in the fileExternal files
may be huge, and I'd like to stream them. I create an
accumulator, stream input files using this accumulator.<xsl:accumulator 
name="acc"
as="map(xs:string, xs:string)"
initial-value="map{}">
                                                                          
 <xsl:accumulator-rule
match="*[@value]">
                                                                              
<xsl:sequence
select="map:put($value, ./local-name(),
xs:string(./@value))"/>
                                                                          
 </xsl:accumulator-rule>
                                                                        
</xsl:accumulator>
                                                                        
                                                                                
 
                                                                
                                                        
                                                
                                                
                                                         
                                                I don't see what this 
accumulator is
matching - there are no @value attributes in your input.
                                                
                                                        
                                                                
                                                                        
<xsl:mode name="m"
streamable="yes"/><xsl:template
match="/">
                                                        
                                                
                                                
                                                        What is "/" here? 
What's the input file?
                                                
                                                
                                                        
                                                                
                                                                         
 <xsl:stream
href="../../test/resources/entries.xml"
use-accumulators="acc">
                                                        
                                                
                                                
                                                        What is entries.xml 
here? Is it the same as source.xml?
                                                
                                                
                                                        
                                                                
                                                                         
    <xsl:apply-templates mode="m"/>
                                                                          
 </xsl:stream>
                                                                           <!-- 
do here something that uses the accumulator
-->
                                                                        
</xsl:template>How can I access to the accumulator after
stream processing ? I'd like to write the map content
to the output. Is it possible ?
                                                                        
                                                                                
 
                                                                
                                                        
                                                
                                                If the only thing you need to 
do is
to create this map, then you don't need accumulators:
                                        
                                                 
                                        
                                                <xsl:map>
                                        
                                                <xsl:for-each
select="doc('source.xml')/root/input">
                                        
                                                  <xsl:map-entry key="@href">
                                        
                                                    <xsl:stream href="{@href}">
                                        
                                                      <xsl:value-of
select="/*/@type"/>
                                        
                                                   </xsl:stream>
                                        
                                                 </xsl:map-entry>
                                        
                                                </xsl:for-each>
                                        
                                                </xsl:map>
                                        
                                                 
                                        
                                                If you want to do other 
processing on the n.xml file then I would
need to see what that processing is, but it's going to be a bit
tricky because accumulators only really work within the context of a
single document.
                                        
                                                 
                                        
                                                Michael Kay
                                        
                                                Saxonica
                                
                        
                
        
--~----------------------------------------------------------------
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>