|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Making a lookup structure from multiple documents
Based on the resulting <map-data> element, your solution gives me what I
need:
<?xml version="1.0" encoding="UTF-8"?>
<map-data>
<all>
<tool quantity="1">Tool1</tool>
<spare quantity="1">Spare1</spare>
<spare quantity="3">Spare2</spare>
<spare quantity="1">Spare3</spare>
<supply quantity="1">Supply1</supply>
<tool quantity="1">Tool1</tool>
<spare quantity="1">Spare1</spare>
<spare quantity="3">Spare2</spare>
<spare quantity="1">Spare3</spare>
<supply quantity="1">Supply1</supply>
</all>
<summary>
<tool quantity="2">Tool1</tool>
<spare quantity="2">Spare1</spare>
<spare quantity="6">Spare2</spare>
<spare quantity="2">Spare3</spare>
<supply quantity="2">Supply1</supply>
</summary>
</map-data>
Here is the modified stylesheet:
<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"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
exclude-result-prefixes="xs math map"
version="3.0" expand-text="yes">
<xsl:output indent="yes"/>
<xsl:accumulator name="summary-data" initial-value="()" as="element()*">
<xsl:accumulator-rule
match="*[@href[matches(.,'(dita(map)?|xml)$','i')][doc-available(.)]]">
<xsl:sequence select="$value"/>
<xsl:apply-templates select="doc(@href)" mode="collect"/>
</xsl:accumulator-rule>
<xsl:accumulator-rule match="tool" select="$value, ." />
<xsl:accumulator-rule match="spare" select="$value, ." />
<xsl:accumulator-rule match="supply" select="$value, ." />
</xsl:accumulator>
<xsl:mode name="collect" on-no-match="shallow-skip"
use-accumulators="summary-data"/>
<xsl:template match="/" mode="collect">
<xsl:apply-templates mode="#current"/>
<xsl:sequence select="accumulator-after('summary-data')"/>
</xsl:template>
<xsl:template match="/">
<map-data>
<!--<xsl:apply-templates/>-->
<all>
<xsl:for-each select="accumulator-after('summary-data')">
<xsl:element name="{local-name(.)}"><xsl:attribute
name="quantity" select="./@quantity"/>{.}</xsl:element>
</xsl:for-each>
</all>
<summary>
<xsl:for-each-group select="accumulator-after('summary-data')"
group-by=".">
<xsl:element name="{local-name(.)}"><xsl:attribute
name="quantity" select="sum(current-group()/@quantity)"/>{.}</xsl:element>
</xsl:for-each-group>
</summary>
</map-data>
</xsl:template>
<xsl:mode on-no-match="shallow-skip" use-accumulators="summary-data"/>
</xsl:stylesheet>
Thank you very much Martin! I appreciate your generous help.
Rick
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








