Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 21st, 2008, 05:00 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default grouping and result-document help

I'm using XSLT 2.0 and Saxon 9B.
I process xml files present in two directories and produce the output xml files, through result-document(). This is done by passing a parameter (<AIDtype> element value). I tried to use for-each-group, but I can't get the needed output.
For IPCC as parameter value,
1st input xml:
<?xml version="1.0" encoding="UTF-8"?>
<Section>
    <Chapter>
    <Chapter><Head>IPCC</Head>
    <test><Head>IPCC Provisioning</Head>
        <Feature>IPCC-Prov</Feature>
        <AIDType>IPCC</AIDType>
        <SectionID>0001</SectionID>
        <check cmdType = "Create"><Head></Head></check>
        <check cmdType = "Retrieve"><Head></Head></check></test>
    <test><Head>IPCC Alarm Provisioning</Head>
        <Feature>IPCC-Alarms</Feature>
        <AIDType>IPCC</AIDType>
        <SectionID>0001</SectionID>
        <check cmdType = "Set"><Head></Head></check>
        <check cmdType = "Retrieve"><Head></Head></check>
    </test></Chapter></Chapter></Section>

2nd input file:
<?xml version="1.0" encoding="UTF-8"?>
<Section><Chapter><Head>Neighbour Discovery</Head>
<Chapter><Head>IPCC</Head>
<test><Head>IPCC Provisioning</Head>
<Feature>IPCC-Prov</Feature>
<AIDType>IPCC</AIDType>
<ratttable>
<rattrow attrfield = "1">
<rattcell><TL1Commands cmdType = "Create">M</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Retrieve">O</TL1Commands></rattcell>
</rattrow>
</ratttable></test>
 <test><Head>IPCC Provisioning</Head>
  <Feature>IPCC-Alarms</Feature>
  <AIDType>IPCC</AIDType>
  <ratttable>
   <rattrow attrfield = "1">
    <rattcell><TL1Commands cmdType = "Set">M</TL1Commands></rattcell>
    <rattcell><TL1Commands cmdType = "Retrieve">O</TL1Commands></rattcell>
   </rattrow>
  </ratttable></test>
</Chapter></Chapter></Section>

XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:param name="repoDirectory"/>
    <xsl:param name="implDirectory"/>

    <xsl:param name="implAIDTypeTag"/>

    <xsl:output indent="yes" method="xml" version="1.1"/>

    <xsl:variable name="implSubTree" select="collection(concat($implDirectory,'/?select=*.xml'))"/>
    <xsl:variable name="repoSubTree" select="collection(concat($repoDirectory,'/?select=*.xml'))"/>

    <xsl:template match="/">
                <xsl:apply-templates select="$implSubTree//test[.//AIDType = $implAIDTypeTag]" mode="doNE"/>
    </xsl:template>



    <xsl:template match="test" mode="doNE">

        <xsl:variable name="Feature" select="Feature"/>
        <xsl:variable name="repoSection" select="$repoSubTree//test[./AIDType = $implAIDTypeTag][./Feature = $Feature]"/>
        <xsl:variable name="implSection" select="."/>
        <xsl:variable name="AIDType" select="./AIDType"/>

        <xsl:for-each-group select="check" group-by="@cmdType">
<xsl:variable name="file" select="concat(@cmdType, '-',$Feature,'.xml')"></xsl:variable>
<xsl:result-document href="{$file}">

        <xsl:apply-templates select="current-group()">
            <xsl:with-param name="repoSection" select="$repoSection"/>
            <xsl:with-param name="implSection" select="$implSection"/>
        </xsl:apply-templates>
            </xsl:result-document>
</xsl:for-each-group>
    </xsl:template>

    <xsl:template match="check">
        blah blah
    </xsl:template>


</xsl:stylesheet>

When I use the above stylesheet model, i can group by @cmdType w.r.t. <Feature>. Because of this I get two xml files, namely Retrieve-IPCC-Alarms.xml and Retrieve-IPCC-Prov.xml. I need to group all under same @cmdType.
The total output files should be Retrieve.xml, Create.xml and Set.xml only. But if I use the above type of grouping I get 4 output files. Is there any way? Any help is appreciated.





------
Rummy
__________________
Rummy
 
Old October 21st, 2008, 05:09 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You're doing the grouping within each test element, whereas from your description (which I don't fully understand) it sounds as if you want to group across test elements. If that's the case then you clearly can't do it within a match="test" template. You need to do the for-each-group at a higher level, before processing the individual test elements.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old October 21st, 2008, 11:01 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Thanks Mike

------
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView and SQL More than one result = one result DarkForce ASP.NET 2.0 Basics 0 July 20th, 2007 04:29 AM
SAXON - result-document bonekrusher XSLT 3 May 7th, 2007 08:27 AM
xsl:result-document instruction bonekrusher XSLT 3 April 12th, 2007 06:01 PM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
xsl grouping aiyer0912 XSLT 9 November 7th, 2006 12:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.