 |
| 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
|
|
|
|

February 6th, 2006, 10:31 AM
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<xsl:key> prints extra string?
Hi all
I use this key in my xsl
<xsl:key name="documents-by-id" match="listrow" use="documentid"/>
on the xml below and when I use a step-by-step debugger the above key line prints out 01 from the <id> and <listtype> respectively, why? How do I avoid it?
<list>
<id>0</id>
<title/>
<listtype>1</listtype>
<category/>
<description/>
<listrows>
<listrow>
<documentid>DDMM64DETM</documentid>
<documenttitle>dsfsdf</documenttitle>
<documentversion>3. 0</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256EAF0045465C/(InternalAdmin)/Frameset?OpenDocument&docUNID=1F1F30C686A4E7E6 C1256F020045900B</documenturl>
<documentmimetype>Anm#228;lan</documentmimetype>
<documentdescription>adfsdf</documentdescription>
<documentpublisheddate/>
<documentauthor>Marja Abrahamsson</documentauthor>
</listrow>
<listrow>
<documentid>DDMM62DKET</documentid>
<documenttitle>tesdokument400</documenttitle>
<documentversion>1. 0</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256EAF0045465C/(InternalAdmin)/Frameset?OpenDocument&docUNID=A315655FC7802D72 C1256EC10051B78A</documenturl>
<documentmimetype>Anbud</documentmimetype>
<documentdescription/>
<documentpublisheddate/>
<documentauthor>Ementor</documentauthor>
</listrow>
<listrow>
<documentid>DDMM64DFKD</documentid>
<documenttitle>dsfdsfasdfasfsfsf</documenttitle>
<documentversion>1. 3</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256EAF0045465C/(InternalAdmin)/Frameset?OpenDocument&docUNID=76CEB9C058EF64B5 C1256F0200326B33</documenturl>
<documentmimetype>Anbud</documentmimetype>
<documentdescription>test</documentdescription>
<documentpublisheddate/>
<documentauthor>Ementor</documentauthor>
</listrow>
<listrow>
<documentid>DDMM62DHKG</documentid>
<documenttitle>testdokument100</documenttitle>
<documentversion>1. 0</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256EAF0045465C/(InternalAdmin)/Frameset?OpenDocument&docUNID=E503FE01B9444B95 C1256EC10048E912</documenturl>
<documentmimetype>Anbud</documentmimetype>
<documentdescription/>
<documentpublisheddate/>
<documentauthor>Ementor</documentauthor>
</listrow>
<listrow>
<documentid>DDMM63ZCC3</documentid>
<documenttitle>Anne Test1</documenttitle>
<documentversion>4. 0</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256EAF0045465C/(InternalAdmin)/Frameset?OpenDocument&docUNID=C51CDE52BF62EE7A C1256EF50039146C</documenturl>
<documentmimetype>Anbud</documentmimetype>
<documentdescription>s1</documentdescription>
<documentpublisheddate/>
<documentauthor>Linda K Svensson</documentauthor>
</listrow>
<listrow>
<documentid>DDMM64LB8D</documentid>
<documenttitle>Test_2004_del03</documenttitle>
<documentversion>1. 0</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256EAF0045465C/(InternalAdmin)/Frameset?OpenDocument&docUNID=EC602358E08A92E0 C1256F08002D729A</documenturl>
<documentmimetype>Formul#228;r</documentmimetype>
<documentdescription/>
<documentpublisheddate/>
<documentauthor>Ementor</documentauthor>
</listrow>
<listrow>
<documentid>DDMM65SB8U</documentid>
<documenttitle>Fikarutiner</documenttitle>
<documentversion>1. 0</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256EA700428A98/(InternalAdmin)/Frameset?OpenDocument&docUNID=94D2C241E599762E C1256F2E002C62F9</documenturl>
<documentmimetype>Anvisning</documentmimetype>
<documentdescription/>
<documentpublisheddate/>
<documentauthor>Marianne Elling</documentauthor>
</listrow>
<listrow>
<documentid>DDMM6AXDJJ</documentid>
<documenttitle>Dagen efter p#229;sk</documenttitle>
<documentversion>2. 0</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256FD3002A4A07/(InternalAdmin)/Frameset?OpenDocument&docUNID=E66668CFB6334558 C1256FD300454469</documenturl>
<documentmimetype>Anm#228;lan</documentmimetype>
<documentdescription>Dokument att godk#228;nna</documentdescription>
<documentpublisheddate/>
<documentauthor>Britt Rolfson</documentauthor>
</listrow>
<listrow>
<documentid>DDMM65ASPG</documentid>
<documenttitle>test_Me_01</documenttitle>
<documentversion>1. 0</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256EAF0045465C/(InternalAdmin)/Frameset?OpenDocument&docUNID=B1D602C320DC77AF C1256F1E0073AA03</documenturl>
<documentmimetype>Anbud</documentmimetype>
<documentdescription>e</documentdescription>
<documentpublisheddate/>
<documentauthor>Ementor</documentauthor>
</listrow>
<listrow>
<documentid>DDMM64LAQK</documentid>
<documenttitle>Lindas 3 7sept</documenttitle>
<documentversion>2. 0</documentversion>
<documenturl>http://ddocm.vgregion.se/C1256EAF0045465C/(InternalAdmin)/Frameset?OpenDocument&docUNID=A588D57E1D0EA54D C1256F08002BFC63</documenturl>
<documentmimetype>Anvisning</documentmimetype>
<documentdescription>testar</documentdescription>
<documentpublisheddate/>
<documentauthor>Linda K Svensson</documentauthor>
</listrow>
</listrows>
</list>
|
|

February 6th, 2006, 10:46 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Which debugger, it certainly works in Visual Studio?
Sounds more like the built-in templates are creating that output, what is your XSLT?
--
Joe ( Microsoft MVP - XML)
|
|

February 6th, 2006, 10:57 AM
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
This is my XSL, but my oxygen debugger shows that it is this row that prints it...
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt" version="2.0">
<xsl:output method="html"/>
<xsl:variable name="showOnlyLatestVersion" select="'false'"/>
<xsl:variable name="sortEntity" select="'documentpublisheddate'"/>
<xsl:variable name="sortOrder" select="'ascending'"/>
<xsl:variable name="showCheckBox" select="'true'"/>
<xsl:variable name="checkBoxTDWidth" select="30"/>
<xsl:variable name="showCopyIcon" select="'true'"/>
<xsl:variable name="copyIconTDWidth" select="30"/>
<xsl:variable name="showProfileIcon" select="'true'"/>
<xsl:variable name="profileIconTDWidth" select="30"/>
<xsl:variable name="showDocumentTitle" select="'true'"/>
<xsl:variable name="documentTitleTDWidth" select="250"/>
<xsl:variable name="showDocumentType" select="'true'"/>
<xsl:variable name="documentTypeTDWidth" select="60"/>
<xsl:variable name="showDocumentVersion" select="'true'"/>
<xsl:variable name="documentVersionTDWidth" select="60"/>
<xsl:variable name="showDocumentPublishedDate" select="'true'"/>
<xsl:variable name="documentPublishedDateTDWidth" select="80"/>
<xsl:variable name="showDocumentAuthor" select="'false'"/>
<xsl:variable name="documentAuthorTDWidth" select="100"/>
<xsl:variable name="showDocumentResponsible" select="'true'"/>
<xsl:variable name="documentResponsibleTDWidth" select="100"/>
<xsl:variable name="showDocumentId" select="'true'"/>
<xsl:variable name="documentIdTDWidth" select="80"/>
<xsl:variable name="showDocumentDescription" select="'true'"/>
<xsl:variable name="documentDescriptionTDWidth" select="600"/>
<xsl:variable name="title" select="'Sökresultat'"/>
<!--
För snabbare gruppering skapas ett index/nyckel på alla dokument
med documentid som nyckel.
-->
<xsl:key name="documents-by-id" match="listrow" use="documentid"/>
<xsl:template match="listrow">
<html>
<head/>
<body>
<xsl:if test="$showOnlyLatestVersion='true'">
<xsl:variable name="latestVersions">
<latestVersionDocuments>
<!-- Alternativ for-each sats
<xsl:for-each select="document[generate-id() =
generate-id(key('documents-by-id', documentid)[1])]">
-->
<!-- Gruppering "Muenchian method"
Gruppera alla dokument per dokumentid, sortera sedan varje grupp fallande på
versionsnummer och plocka ut första förekomsten i varje grupp som motsvarar
senaste versionen för varje documentid
-->
<xsl:for-each select="listrow[count(. | key('documents-by-id',
documentid)[1]) = 1]">
<xsl:for-each select="key('documents-by-id', documentid)">
<xsl:sort select="documentversion" data-type="number"
order="descending"/>
<xsl:if test="position() = 1">
<xsl:copy-of select="current()"/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</latestVersionDocuments>
</xsl:variable>
<!-- Generera html för dokumenten i variabeln latestVersions
(Choose-satsen ser ut som nedan eftersom sort måste syntaxmässigt ligga i
direkt anslutning till apply-templates).
"select"-attributet till apply-templates förebygger en bugg i xslt-processorn som ibland skriver ut dubbla poster.
-->
<xsl:choose>
<xsl:when test="$sortEntity = 'documenttitle' and $sortOrder='ascending'">
<xsl:apply-templates
select="$latestVersions//listrow[not(following-sibling::node()/documentid
= documentid)]">
<xsl:sort data-type="text" select="documenttitle" order="ascending"
/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$sortEntity = 'documenttitle' and $sortOrder='descending'">
<xsl:apply-templates
select="$latestVersions//listrow[not(following-sibling::node()/documentid
= documentid)]">
<xsl:sort data-type="text" select="documenttitle" order="descending"
/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$sortEntity = 'documentpublisheddate' and
$sortOrder='ascending'">
<xsl:apply-templates
select="$latestVersions//listrow[not(following-sibling::node()/documentid
= documentid)]">
<xsl:sort data-type="text" select="documentpublisheddate"
order="ascending"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$sortEntity = 'documentpublisheddate' and
$sortOrder='descending'">
<xsl:apply-templates
select="$latestVersions//listrow[not(following-sibling::node()/documentid
= documentid)]">
<xsl:sort data-type="text" select="documentpublisheddate"
order="descending"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</xsl:if>
<xsl:if test="not($showOnlyLatestVersion='true')">
<!-- Generera html för dokumenten i variabeln latestVersions
(Choose-satsen ser ut som nedan eftersom sort måste syntaxmässigt ligga i
direkt anslutning till apply-templates).
-->
<xsl:choose>
<xsl:when test="$sortEntity = 'documenttitle' and $sortOrder='ascending'">
<xsl:apply-templates select="listrow">
<xsl:sort data-type="text" select="documenttitle" order="ascending"
/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$sortEntity = 'documenttitle' and $sortOrder='descending'">
<xsl:apply-templates select="listrow">
<xsl:sort data-type="text" select="documenttitle" order="descending"
/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$sortEntity = 'documentpublisheddate' and
$sortOrder='ascending'">
<xsl:apply-templates select="listrow">
<xsl:sort data-type="text" select="documentpublisheddate"
order="ascending"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$sortEntity = 'documentpublisheddate' and
$sortOrder='descending'">
<xsl:apply-templates select="listrow">
<xsl:sort data-type="text" select="documentpublisheddate"
order="descending"/>
</xsl:apply-templates>
</xsl:when>
</xsl:choose>
</xsl:if>
</body>
</html>
</xsl:template>
<xsl:template match="listrow">
<table border="0">
<tr>
<xsl:if test="$showCheckBox='true'">
<td width="{$checkBoxTDWidth}" valign="top">
<input type="checkbox"/>
</td>
</xsl:if>
<xsl:if test="$showCopyIcon='true'">
<td width="{$copyIconTDWidth}" valign="top"> C </td>
</xsl:if>
<xsl:if test="$showProfileIcon='true'">
<td width="{$profileIconTDWidth}" valign="top"> i </td>
</xsl:if>
<xsl:if test="$showDocumentTitle='true'">
<td width="{$documentTitleTDWidth}" valign="top">
<xsl:value-of select="documenttitle"/>
</td>
</xsl:if>
<xsl:if test="$showDocumentType='true'">
<td width="{$documentTypeTDWidth}" valign="top">
<xsl:value-of select="documentmimetype"/>
</td>
</xsl:if>
<xsl:if test="$showDocumentVersion='true'">
<td width="{$documentVersionTDWidth}" valign="top">
<xsl:text>Ver </xsl:text>
<xsl:value-of select="documentversion"/>
</td>
</xsl:if>
<xsl:if test="$showDocumentPublishedDate='true'">
<td width="{$documentPublishedDateTDWidth}" valign="top">
<xsl:value-of select="documentpublisheddate"/>
</td>
</xsl:if>
<xsl:if test="$showDocumentAuthor='true'">
<td width="{$documentAuthorTDWidth}" valign="top">
<xsl:value-of select="documentauthor"/>
</td>
</xsl:if>
<xsl:if test="$showDocumentResponsible='true'">
<td width="{$documentResponsibleTDWidth}" valign="top">
<xsl:value-of select="documentresponsible"/>
</td>
</xsl:if>
<xsl:if test="$showDocumentId='true'">
<td width="{$documentIdTDWidth}" valign="top">
<xsl:value-of select="documentid"/>
</td>
</xsl:if>
</tr>
</table>
<xsl:if test="$showDocumentDescription='true'">
<table border="0">
<tr>
<xsl:if test="$showCheckBox='true'">
<td width="{$checkBoxTDWidth}" valign="top"/>
</xsl:if>
<xsl:if test="$showCopyIcon='true'">
<td width="{$copyIconTDWidth}" valign="top"/>
</xsl:if>
<xsl:if test="$showProfileIcon='true'">
<td width="{$profileIconTDWidth}" valign="top"/>
</xsl:if>
<xsl:if test="$showDocumentDescription='true'">
<td width="{$documentDescriptionTDWidth}" valign="top">
<xsl:value-of select="documentdescription"/>
</td>
</xsl:if>
</tr>
</table>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
|
|

February 6th, 2006, 11:30 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
If your stylesheet is (apparently) producing the wrong output, you need to show us your stylesheet.
If your debugger is producing the wrong output, you need to complain to the vendor that sold you the debugger.
I'm a little surprised that any debugger should ever show xsl:key as an executable statement, but of course the design is up to them.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

February 6th, 2006, 11:40 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Well, your code is certainly doing some strange things.
For a start, it has two templates specifying <xsl:template match="listrow"/>.
I suspect the first one is meant to be match="/", but you then do
select="document[...]"
and I don't see an element called "document" anywhere in your input.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

February 6th, 2006, 11:48 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
|
|
Without wading through the whole XSLT it appears that the built-in templates are producing the extraneous output. In Visual Studio it looks similar but as you can't really set a breakpoint on the key element shows that this is not the case, it actually puts in the values before hitting the first template.
One way to get rid of the extra bits is to add an extra empty template, try the following w9th and without the second template:
Code:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="documents-by-id" match="listrow" use="documentid"/>
<xsl:template match="listrow">
<xsl:copy-of select="."/>
</xsl:template>
<xsl:template match="list/*[not(listrow)]"/>
</xsl:stylesheet>
I'm sure Michael can show us something more elegant.
--
Joe ( Microsoft MVP - XML)
|
|

February 6th, 2006, 12:13 PM
|
|
Registered User
|
|
Join Date: Jan 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
SOLVED!
The <xsl:template match="list/*[not(listrow)]"/> helped me out.
Micheal, the first <xsl:template match="listrow"/> should have been <xsl:template match="listrows"/>. Sorry.
Thanks for your help!
and don't dig to deep in my xsl. These are my first step in xslt...
|
|
 |