[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] How to properly use Key elements


Subject: Re: [xsl] How to properly use Key elements
From: Emmanuel Bégué <medusis@xxxxxxxxx>
Date: Wed, 16 Oct 2013 07:46:46 +0200

Hello,

I don't understand what keys are supposed to achieve in this case?

The following solution produces the desired output without keys:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>

<xsl:template match="/table">
  <xsl:apply-templates/>
  </xsl:template>

<xsl:template match="*">
  <xsl:apply-templates/>
  </xsl:template>

<xsl:template match="thead|text()"/>

<xsl:template match="tr[1]">
  <!-- beware, the ship name should be a valid element name (no
spaces, etc.) -->
  <xsl:variable name="shipName" select="td[1]"/>
  <xsl:element name="{$shipName}">
    <xsl:apply-templates select="following-sibling::tr" mode="port"/>
    </xsl:element>
  </xsl:template>

<xsl:template match="tr" mode="port">
  <xsl:variable name="numRows" select="count(td)"/>
  <xsl:for-each select="td[$numRows - 1]">
    <port name="{.}">
      <xsl:value-of select="following-sibling::td[1]"/>
        </port>
    </xsl:for-each>
  </xsl:template>

</xsl:stylesheet>

This may be the solution you're refering to in your last paragraph,
and maybe the input is really more complex than the example given; but
if the structure is similar, this should be fast enough even on a long
input file...?

Regards,
EB

On Wed, Oct 16, 2013 at 1:35 AM, G. T. Stresen-Reuter
<tedmasterweb@xxxxxxxxx> wrote:


Current Thread