Paul Bergström
Paul Bergström

Reputation: 253

Having a minor XSLT issue

I have a XSL stylesheet working perfectly well in Mozilla Firefox 45 where I made a template like this:

<xsl:template match="//case/events/event/document">
    <a href="{@xlink:href}">
        <xsl:value-of select="@xlink:href"/>
    </a>
</xsl:template>

Further down in the stylesheet I call this template with:

<xsl:apply-templates select="//case/events/event/document"/>

In Firefox it works fine, but in Google Chrome 49 and Internet Explorer 9 the contence of the template is displayed directly in the head of the page and not further down the page as in Firefox (and as intended). Any ideas?

Many thanks in advance:-)

/Paul


Just to clarify. The link should be displayed in it's correct place in the table as in Firefox, but in Chrome and Explorer the link is shown immediately in top of the page and it's place in the table is blank.

Here is the full stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Document   : arende.xsl
  Created on : 6 april, 2016
  Author     : Paul Bergström
-->
<!--
  Declaration of usage of XLink Namespace
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink" exclude-result-prefixes="xlink" version="1.0">
<xsl:output method="html"/>
<!--
Attribute XLink defined as an href of simple type
-->
<xsl:template match="*[@xlink:type = 'simple' and @xlink:href]">
    <a href="{@xlink:href}">
        <xsl:apply-templates/>
    </a>
</xsl:template>
     <xsl:template match="//case/events/event/document">
    <a href="{@xlink:href}">
        <xsl:value-of select="@xlink:href"/>
    </a>
</xsl:template>
  <xsl:template match="//case/events/event/document/attachments/attachment">
    <a href="{@xlink:href}">
        <xsl:value-of select="@xlink:href"/>
    </a>
</xsl:template>
<xsl:template match="/">
    <html>
        <head>
            <title>Ärendekort</title>
        </head>
        <body>
            <h2>Ärende</h2>
            <!--xsl:apply-templates select="case"/-->
        </body>
        </html>
<!--xsl:template match="case"-->
    <table border="1" max-width="100%">
      <tr bgcolor="#9acd32">
        <th>Element namn</th>
        <th>Innehåll</th>
      </tr>
        <xsl:for-each select="//case/*[not(self::events)]">
    <tr bgcolor="#FBF5A4">
      <td><xsl:value-of select="local-name()" /></td>
      <td><xsl:value-of select="." /></td>
    </tr>
    </xsl:for-each>
        <xsl:for-each select="//case/events/event/*[not(self::document)]">
     <tr bgcolor="#00FFFF">
              <td><xsl:value-of select="local-name()" /></td>
              <td><xsl:value-of select="." /></td>
            </tr>
        </xsl:for-each>
    <xsl:for-each select="//case/events/event/document">
        <tr bgcolor="#00FFFF">
        <td><xsl:value-of select="local-name()" /></td>
        <xsl:apply-templates select="//case/events/event/document"/>
        </tr>
        <tr bgcolor="#00FFFF">          
        <xsl:for-each select="//case/events/event/document/debug_docSource">
        <td><xsl:value-of select="local-name()" /></td>
        <td><xsl:value-of select="." /></td>
        </xsl:for-each>
        </tr>
        <xsl:for-each select="//case/events/event/document/attachments/attachment">
                    <tr bgcolor="#00FFFF">
                    <td><xsl:value-of select="local-name()" /></td>
                    <xsl:apply-templates select="//case/events/event/document/attachments/attachment"/>
                    </tr>
</xsl:for-each>
</xsl:for-each>

    </table>

</xsl:template>
</xsl:stylesheet>

Upvotes: 0

Views: 50

Answers (1)

Tim C
Tim C

Reputation: 70648

Looking at this bit of code...

<xsl:for-each select="//case/events/event/document">
    <tr bgcolor="#00FFFF">
       <td><xsl:value-of select="local-name()" /></td>
       <xsl:apply-templates select="//case/events/event/document"/>
    </tr>

This is going to output HTML like the following:

<tr bgcolor="#00FFFF">
    <td>document</td>
    <a href="http://stackoverflow.com">http://stackoverflow.com</a>
</tr>

So, you have an a tag that is not in a td tag but a direct child of tr. This is what is confusing the browsers. It really should be in a td tag too.

So, it probably should look like this

<xsl:for-each select="//case/events/event/document">
    <tr bgcolor="#00FFFF">
       <td><xsl:value-of select="local-name()" /></td>
       <td><xsl:apply-templates select="//case/events/event/document"/></td>
    </tr>

In fact, you don't really need the full xpath expression in the xsl:apply-templates as you are already positioned on the document element. Try this too

<xsl:for-each select="//case/events/event/document">
    <tr bgcolor="#00FFFF">
       <td><xsl:value-of select="local-name()" /></td>
       <td><xsl:apply-templates select="."/></td>
    </tr>

Upvotes: 1

Related Questions