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 April 6th, 2007, 07:29 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Grouping problem

Hi All,

I am having trouble with a simple grouping template.

XSLT 2.0
Output HTML


I am receiveing the following error in XMLSPY:

"Error in XPath 2.0 expression
Attempting to access the typed value of an element having complex type with element only content. - 'ITEM'"

Here is my XML:
Code:
<ROOT>
<ITEM active="1">
        <NAME>Test Notice Name</NAME>
        <NOTICE>2006-A036</NOTICE>
        <LINK>www.whatever.com</LINK>
        <ISSUED>2006-06-02T00:00:00.000</ISSUED>
        <COMMENTS>Original Conversion</COMMENTS>
        <EXPIRES>2007-09-30</EXPIRES>
</ITEM>
<ITEM active="1">
        <NAME>UPDATES PROCEDURES</NAME>
        <NOTICE>2006-A050TR</NOTICE>
        <LINK>www.whatever.com</LINK>
        <ISSUED>2006-08-25T00:00:00.000</ISSUED>
        <COMMENTS>Original Conversion</COMMENTS>
        <EXPIRES>2007-09-30</EXPIRES>
</ITEM>
<ROOT>
Here is the XSLT:

Code:
                <xsl:for-each-group select="$XML1/ROOT/ITEM" group-by="substring-before(NOTICE, '-')">
                    <xsl:sort select="current-grouping-key()"/>
                    <table width="100%">
                        <tbody>
                            <tr>
                                <td colspan="3">
                                    <a name="{current-grouping-key()}">
                                        <h2>
                                            <xsl:value-of select="current-grouping-key()"/>
                                        </h2>
                                    </a>
                                </td>
                            </tr>
                            <tr align="center" bgcolor="silver" style="font-weight:bold;">
                                <td width="100">Notice</td>
                                <td>Description</td>
                                <td width="125">Issue Date</td>
                            </tr>
                            <xsl:for-each-group select="current-group()" group-by=".">
                                <tr>
                                    <td width="125">
                                        <a href="{link}">
                                            <xsl:value-of select="NOTICE"/>
                                        </a>
                                    </td>
                                    <td>
                                        <xsl:value-of select="upper-case(NAME)"/>
                                    </td>
                                    <td>
                                        <xsl:value-of select="format-number(number(substring(string(ISSUED), 6, 2)), '00')"/>
                                        <xsl:text> / </xsl:text>
                                        <xsl:value-of select="format-number(number(substring(string(ISSUED), 9, 2)), '00')"/>
                                        <xsl:text> / </xsl:text>
                                        <xsl:value-of select="format-number(number(substring(string(string(ISSUED)), 1, 4)), '0000')"/>
                                    </td>
                                </tr>
                            </xsl:for-each-group>
                        </tbody>
                    </table>
                </xsl:for-each-group>


If I remove the @active from the XML, it works, but when its there I get the error. I believe I am recieving the error from this line:

<xsl:for-each-group select="current-group()" group-by=".">


Thanks for the help.
 
Old April 6th, 2007, 05:50 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

I figure it out.

I was trying to sort with an element that did not have a value. Is this correct?
 
Old April 7th, 2007, 11:40 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Within

<xsl:for-each-group select="$XML1/ROOT/ITEM"

the items in current-group are ITEM elements, so when you later do

<xsl:for-each-group select="current-group()" group-by=".">

then "." will be selecting at ITEM element and extracting its typed value. If you're running a schema-aware transformation then I would imagine that ITEM is declared with element-only content, which means that you can't extract its typed value, and you would expect to see this error message. Adding or removing an attribute shouldn't affect this, however - "element-only content" is something that depends on the schema, not on the instance.

(Are you running Altova?)

Irrespective of that, however, what you are doing doesn't make sense. What are you actually trying to group by in the inner for-each-group?

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 7th, 2007, 05:11 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi Michael,

As always you are a great help. I am using XMLspy (2007):

Here is the final grouping:

Code:
<xsl:for-each-group select="$XML1/ROOT/ITEM[@active = 1][not(@ata)]" group-by="substring-before(substring-after(NOTICE, '-'), '0')">
                        <xsl:sort select="current-grouping-key()"/>
                        <xsl:variable name="str" select="substring-before(substring-after(NOTICE, '-'), '0')"/>
                        <xsl:variable name="type">
                            <xsl:choose>
                                <xsl:when test="contains($str, 'ALERT')">ALERTS</xsl:when>
                                <xsl:when test="starts-with($str, 'F')">FLIGHT</xsl:when>
                                <xsl:when test="starts-with($str, 'S')">SAFETY</xsl:when>
                                <xsl:when test="contains($str, 'T')">TECHNICAL</xsl:when>
                                <xsl:when test="contains($str, 'L')">LEARNING</xsl:when>
                                <xsl:otherwise>AIRPORT</xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <span style="font-size:xx-small; color:lightgray; font-family:@Arial Unicode MS;">
                            <p align="right">
                                <a href="#top">[Return to Top]</a>
                            </p>
                        </span>
                        <table width="100%">
                            <tbody>
                                <tr>
                                    <td colspan="3">
                                        <a name="{current-grouping-key()}">
                                            <h2>
                                                <xsl:value-of select="$type"/>
                                            </h2>
                                        </a>
                                    </td>
                                </tr>
                                <tr align="center" bgcolor="silver" style="font-weight:bold;">
                                    <td width="100">Notice</td>
                                    <td>Description</td>
                                    <td width="125">Issue Date</td>
                                </tr>
                                <xsl:for-each-group select="current-group()" group-by="NOTICE">
                                    <tr>
                                        <td width="125">
                                            <a href="{LINK}">
                                                <xsl:value-of select="NOTICE"/>
                                            </a>
                                        </td>
                                        <td>
                                            <xsl:value-of select="upper-case(NAME)"/>
                                        </td>
                                        <td>
                                            <xsl:value-of select="format-number(number(substring(string(ISSUED), 6, 2)), '00')"/>
                                            <xsl:text> / </xsl:text>
                                            <xsl:value-of select="format-number(number(substring(string(ISSUED), 9, 2)), '00')"/>
                                            <xsl:text> / </xsl:text>
                                            <xsl:value-of select="format-number(number(substring(string(string(ISSUED)), 1, 4)), '0000')"/>
                                        </td>
                                    </tr>
                                </xsl:for-each-group>
                            </tbody>
                        </table>
                    </xsl:for-each-group>


The first group, group the department name. The inner grouping displays the <NOTICE> by department.

I am currently converting legacy data to XML. The <NOTICE> element can be broken down by year, department, type etc...


the output looks something like this in html:



 
Code:
AIRPORT
Code:
Notice        Description        Issue Date
2006-AXX    zzz            03 / 31 / 2006
2006-AXXTR    xxx            04 / 13 / 2006
2006-AXXX A    xxx            06 / 02 / 2006

[Return to Top]

ALERTS
Notice        Description    Issue Date
2004-ALERT-XXX    xx        02 / 24 / 2004
2004-ALERT-XXx    xx        04 / 23 / 2004


on so on....
If there is a more efficient way, I am listening :)

thanks





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem of grouping in XSLT LeoMathew XSLT 2 September 11th, 2008 09:38 AM
grouping problem at xslt1.0 joshuaa XSLT 4 July 15th, 2008 08:08 AM
XML Grouping Problem andymidd XSLT 2 July 10th, 2007 02:48 AM
Grouping problem aware Access 11 August 4th, 2005 11:00 AM
grouping and expressions problem parityah BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 May 2nd, 2005 06:43 PM





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