This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Small grouping problem (double HTML output for one node but not for another???)
- To: xsl-list at lists dot mulberrytech dot com
- Subject: [xsl] Small grouping problem (double HTML output for one node but not for another???)
- From: ghostrider <ghostrider at advalvas dot be>
- Date: Wed, 11 Jul 2001 13:59:14 +0200
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi,
I'm having trouble combining 2 pieces of XSL which work as expected when used
as separate xsl files for one single xml file, but give different output
results when i try to combine them - that is, I get nodes that are output
twice when they shouldn't be (because of the GROUPING that one particular XSL
ought to do).
I'm quite sure that the cause for my problems is that the different parts of
the two XSL files are NOT IN THE CORRECT PLACE (although XMLSpy does not give
any syntax errors...)to do what I want the XSL to do.
Someone please have a quick look at these files...
Thanks a lot,
Armin
** CORRECT HTML Output with XSL1 (which groups nodes) **
Input
DPF - Description 1
IPC - Description 2
Ouput
DPF - Description 3
IPC - Description 4
** INCORRECT HTML Output with XSL2 (which also should add an HTML template for
the root, not just the nodes recursively processed and grouped) - Note that
the Input node is output twice, the Output node is output once, as it should
be)**
Release Notes
some text...
some text...
Input
DPF - Description 1
IPC - Description 2
Input
DPF - Description 1
IPC - Description 2
Ouput
DPF - Description 3
IPC - Description 4
** XML file ***
<?xml-stylesheet type="text/xsl"
href="C:\HIGroup\XML\bugs\transform_09-07-01c.xsl"?>
<root>
<Bugs>
<Bug>
<Category1>Input</Category1>
<Category2>DPF</Category2>
<Type>Bug fix</Type>
<Description>Reading in ODB++ somehow ...</Description>
<BugBase>001</BugBase>
</Bug>
<Bug>
<Category1>Input</Category1>
<Category2>IPC</Category2>
<Type>Enhancement</Type>
<Description>Reading in ODB++ somehow ...</Description>
<BugBase>002</BugBase>
</Bug>
<Bug>
<Category1>Output</Category1>
<Category2>IPC</Category2>
<Type>Enhancement</Type>
<Description>Reading in ODB++ somehow ...</Description>
<BugBase>003</BugBase>
</Bug>
</Bugs>
<Calls>
<Call BugBase="001"> B10015 </Call>
<Call BugBase="001"> B10016 </Call>
<Call BugBase="002"> B10017 </Call>
<Call BugBase="003"> B10018 </Call>
<Call BugBase="003"> B10019 </Call>
</Calls>
</root>
** XSL 1 - which generates correct output **
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="categories" match="Bug" use="Category1"/>
<xsl:key name="calls" match="Call" use="@BugBase"/>
<xsl:template match="Bugs">
<xsl:apply-templates select="Bug[generate-id(.) = generate-id(key
('categories', Category1) [1] ) ]" />
</xsl:template>
<xsl:template match="root/Bugs/Bug">
<xsl:value-of select="Category1" />
<div>
<xsl:for-each select="key('categories', Category1)">
<div><xsl:value-of select="Category2" /><xsl:text> - </xsl:text>
<xsl:value-of select="Description" /></div>
<p>
<xsl:for-each select="key('calls', BugBase)">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each></p>
</xsl:for-each> <hr />
</div>
</xsl:template>
<!--Start: no output for Call node-->
<xsl:template match="root/Calls/Call">
</xsl:template>
<!--End: no output for Call node-->
</xsl:stylesheet>
** XSL 2 - generating INCORRECT double output **
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="categories" match="Bug" use="Category1"/>
<xsl:key name="calls" match="Call" use="@BugBase"/>
<xsl:template match="root">
<html>
<body>
<p>Release Notes</a>
<hr style="height:2px;color:navy"/>
</p>
<!-- Bug fix start-->
<xsl:apply-templates select="Bugs/Bug" />
<!-- Bug fix end-->
</body>
</html>
</xsl:template>
<xsl:template match="root/Bugs">
<xsl:apply-templates select="Bug[generate-id(.) = generate-id(key
('categories', Category1) [1] ) ]" />
</xsl:template>
<xsl:template match="Bugs/Bug">
<div>
<b><xsl:value-of select="Category1" /></b>
<div>
<xsl:for-each select="key('categories', Category1)">
<span><p><b><xsl:value-of select="Category2"/> (<xsl:value-of
select="Type"/>)</b></p>
</span>
<div>
<p><xsl:for-each select="key('calls', BugBase)">
<xsl:value-of select="."/>
<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each></p>
<div>
<p><xsl:value-of select="Description"/></p>
</div>
</div>
</xsl:for-each>
</div>
</div>
</xsl:stylesheet>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list