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 May 3rd, 2005, 04:19 AM
Authorized User
 
Join Date: May 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to meetnaveen4u
Default Generate-id problem.

Hi All,
 I have used generate-id function for grouping the elements. I am facing one problem in it.i.e if i have registerid=1, registerid=1, registerid=2. i get grouped value as 1 and 2. and while i am parsing it with xml, for registerid=1 there is different content and for next registerid=1 there is different content. but with this generate-id i only get the first occurance of registerid=1 content. how to get different content for same registerid. If any solution would be great help for me.

Thanks & Regards
Naveen.
__________________
Thanks and Regards
Naveen.
 
Old May 3rd, 2005, 04:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can't expect people to debug your code without seeing it. Produce a small sample showing your input XML, your stylesheet, and your desired output, and someone might tell you where you are going wrong.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 13th, 2005, 12:06 AM
Authorized User
 
Join Date: May 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to meetnaveen4u
Default

Hi All,
I am facing problem or rather dont know correct way for approaching this type of complex grouping problem.
For example.
This is my input file.
<?xml version="1.0" encoding="UTF-8"?>
<product>
    <sale>
        <SB>
            <scc>
                <main>
                    <pos>1</pos>
                    <amount>1.80</amount>
                    <price>1.111</price>
                    <volume>1.624</volume>
                    <gradeid id="1">
                        <name>UNLD</name>
                    </gradeid>
                    <Level id="1">
                        <name>state</name>
                    </Level>
                    <Level id="2">
                        <name>asdf</name>
                    </Level>
                </main>
            </scc>
        </SB>
        <ABB>
            <acc>
                <code sysid="1" id="1">
                    <name>xyz</name>
                </code>
                <amount>2.00</amount>
            </acc>
            <acc>
                <code sysid="1" id="0">
                    <name>acc</name>
                </code>
                <amount>-.20</amount>
            </acc>
        </ABB>
    </sale>
    <checkProduct>
        <id>1</id>
        <name>abc</name>
    </checkProduct>
    <sale>
        <SB>
            <scc>
                <main>
                    <pos>1</pos>
                    <amount>1.80</amount>
                    <price>1.111</price>
                    <volume>1.624</volume>
                    <gradeid id="1">
                        <name>UNLD</name>
                    </gradeid>
                    <Level id="1">
                        <name>state</name>
                    </Level>
                    <Level id="2">
                        <name>asdf</name>
                    </Level>
                    <Level id="3">
                        <name>a</name>
                    </Level>
                </main>
            </scc>
        </SB>
        <ABB>
            <acc>
                <code sysid="1" id="13">
                    <name>xyz</name>
                </code>
                <amount>2.00</amount>
            </acc>
            <acc>
                <code sysid="1" id="0">
                    <name>acc</name>
                </code>
                <amount>-.20</amount>
            </acc>
        </ABB>
    </sale>
    <check>
        <id>2</id>
        <name>abc</name>
    </check>
    <sale>
        <SB>
            <scc>
                <main>
                    <pos>1</pos>
                    <amount>1.80</amount>
                    <price>1.111</price>
                    <volume>1.624</volume>
                    <gradeid id="1">
                        <name>UNLD</name>
                    </gradeid>
                    <Level id="1">
                        <name>state</name>
                    </Level>
                    <Level id="2">
                        <name>asdf</name>
                    </Level>
                    <Level id="3">
                        <name>a</name>
                    </Level>
                </main>
            </scc>
        </SB>
        <ABB>
            <acc>
                <code sysid="1" id="13">
                    <name>xyz</name>
                </code>
                <amount>2.00</amount>
            </acc>
            <acc>
                <code sysid="1" id="0">
                    <name>acc</name>
                </code>
                <amount>-.20</amount>
            </acc>
        </ABB>
    </sale>
    <check>
        <id>2</id>
        <name>abc</name>
    </check>
    <sale>
        <SB>
            <scc>
                <main>
                    <pos>1</pos>
                    <amount>1.80</amount>
                    <price>1.122</price>
                    <volume>1.624</volume>
                    <gradeid id="1">
                        <name>UNLD</name>
                    </gradeid>
                    <Level id="1">
                        <name>state</name>
                    </Level>
                    <Level id="2">
                        <name>asdf</name>
                    </Level>
                    <Level id="3">
                        <name>a</name>
                    </Level>
                </main>
            </scc>
        </SB>
        <ABB>
            <acc>
                <code sysid="1" id="13">
                    <name>xyz</name>
                </code>
                <amount>2.00</amount>
            </acc>
            <acc>
                <code sysid="1" id="0">
                    <name>acc</name>
                </code>
                <amount>-.20</amount>
            </acc>
        </ABB>
    </sale>
    <sale>
        <SB>
            <scc>
                <main>
                    <pos>1</pos>
                    <amount>1.3</amount>
                    <price>1.122</price>
                    <volume>1.55</volume>
                    <gradeid id="1">
                        <name>UNLD</name>
                    </gradeid>
                    <Level id="1">
                        <name>state</name>
                    </Level>
                    <Level id="2">
                        <name>asdf</name>
                    </Level>
                </main>
            </scc>
        </SB>
        <ABB>
            <acc>
                <code sysid="1" id="12">
                    <name>xyz</name>
                </code>
                <amount>2.00</amount>
            </acc>
            <acc>
                <code sysid="1" id="0">
                    <name>acc</name>
                </code>
                <amount>-.20</amount>
            </acc>
        </ABB>
    </sale>
</product>
I am generating output file as another xml file.
Excepted output file is...

<productSale xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<productDetails>
        <productCode>1</productCode>
        <productID>1</productID>
        <PriceSummary>
            <priceCode>1.111</priceCode>
                        <details>
                          <Level>1</Level>
                          <amt>1.80</amt>
                          <volume>1.624</volume>
                        </details>
                        <details>
              <Level>2</Level>
              <amt>1.80</amt>
              <volume>1.624</volume>
                        </details>
        </PriceSummary>
    </productDetails>
    <productDetails>
        <productCode>1</productCode>
        <productID>13</productID>
        <PriceSummary>
            <priceCode>1.111</priceCode>
            <details>
              <Level>1</Level>
              <amt>3.6</amt>
              <volume>3.248</volume>
            </details>
            <details>
              <Level>2</Level>
              <amt>3.6</amt>
              <volume>3.248</volume>
            </details>
            <details>
              <Level>3</Level>
              <amt>3.6</amt>
              <volume>3.248</volume>
            </details>
            <priceCode>1.122</priceCode>
            <details>
              <Level>1</Level>
              <amt>3.6</amt>
              <volume>3.248</volume>
            </details>
            <details>
              <Level>2</Level>
              <amt>3.6</amt>
              <volume>3.248</volume>
            </details>
            <details>
              <Level>3</Level>
              <amt>3.6</amt>
              <volume>3.248</volume>
            </details>
        </PriceSummary>
    </productDetails>
    <productDetails>
        <productCode>1</productCode>
        <productID>13</productID>
        <PriceSummary>
            <priceCode>1.122</priceCode>
            <details>
              <Level>1</Level>
              <amt>3.6</amt>
              <volume>3.248</volume>
            </details>
            <details>
              <Level>2</Level>
              <amt>3.6</amt>
              <volume>3.248</volume>
            </details>
            <details>
              <Level>3</Level>
              <amt>3.6</amt>
              <volume>3.248</volume>
            </details>
        </PriceSummary>
    </productDetails>
    <productDetails>
        <productCode>1</productCode>
        <productID>12</productID>
        <PriceSummary>
            <priceCode>1.122</priceCode>
                        <details>
                          <Level>1</Level>
                          <amt>1.3</amt>
                          <volume>1.55</volume>
                        </details>
                        <details>
              <Level>2</Level>
              <amt>1.3</amt>
              <volume>1.55</volume>
                        </details>
        </PriceSummary>
    </productDetails>
</productSale>

How to do complex grouping like this to get the output.
my code only generates unique code for productCode and then when i am trying to get unique productID for this productCode i am failing. And
even i have the group again with priceCode, so there will be composite key (productCode, productID, priceCode) for each variation of this
key values there will be productDetails respectively.

My code is as follows.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2004/07/xpath-functions" xmlns:xdt="http://www.w3.org/2004/07/xpath-datatypes">
<xsl:key name="grade_key" match="sale" use="SB/scc/main/gradeid/@id"/>
<xsl:key name="code_key" match="sale" use="ABB/acc/code/@id"/>
<xsl:template match="/product">
<productSale>
<xsl:for-each select="sale[generate-id(.)=generate-id(key('grade_key',SB/scc/main/gradeid/@id)) or generate-id(.)=generate-id(key('code_key',ABB/acc/code/@id))]">
inside sale
    <xsl:if test="SB/scc/main">
    <xsl:variable name="saleNode" select="."/>
        <xsl:for-each select="ABB/acc[position()=1]/code">

        <xsl:call-template name="dispProductDetail">
        <xsl:with-param name="saleNode" select="$saleNode"/>
        </xsl:call-template>
        </xsl:for-each>
    </xsl:if>
</xsl:for-each>
</productSale>
</xsl:template>
<xsl:template name="dispProductDetail">
    <xsl:param name="saleNode"/>
    <productDetails>
        <productCode><xsl:value-of select="$saleNode/SB/scc/main/gradeid/@id"/> </productCode>
        <productID><xsl:value-of select="$saleNode/ABB/acc/code/@id"/> </productID>
        <PriceSummary>
            <priceCode><xsl:value-of select="$saleNode/SB/scc/main/price"/></priceCode>
        </PriceSummary>
    </productDetails>
</xsl:template>
</xsl:stylesheet>

Please help me as i am trying this from past 1 week. This would be the great help
Thanks in advance.
Naveen.

Thanks &amp; Regards
Naveen.





Similar Threads
Thread Thread Starter Forum Replies Last Post
generate unique id capri SQL Server 2000 1 April 6th, 2008 10:18 AM
generate id grouping using xslt meetnaveen4u XSLT 0 May 23rd, 2005 05:14 AM
How to Auto Generate ID (Primary Key) SQL Database havering SQL Server ASP 1 December 9th, 2004 05:33 AM
How to Auto Generate ID (Primary Key) SQL database havering SQL Server 2000 9 December 1st, 2004 10:38 AM
Generate unique ID when populating a table sroman SQL Server 2000 2 August 5th, 2003 03:38 AM





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