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

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"

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

<xsl:template match="/table">

<xsl:template match="*">

<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: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]"/>


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


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

Current Thread