David,

Fidling around a bit brought me to the XSL you will find below. Some notes 
though.

Particularly the part that multiple values have to be added to the same attribute makes it quite difficult. I have for convenience chosen to add separate class elements to the img content. You could merge these to a class attribute with a separate transform.

I am very sure this stylesheet can be optimized a lot. It now has to iterate through as many modes as there are xpaths + 2, which is not good for performance. This could be optimizes if more knowledge is added to the xpaths.xml. For instance by clustering less and more exact matches into a group and converting the matches in this group to a choose construct inside a template.

I hope this XSL gives you a jump start or can give you some inspiration for 
futher problems..

By the way, I saw your cross post on the dev list and am curious to the STX 
solution as well.

Cheers,
Geert

<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id$ -->

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:myxsl="http://www.w3.org/1999/XSL/TransformAlias";

    xmlns:xpaths="xpaths"
    xmlns:xhtml="xhtml"
>

<!--+ ==============================================================
    | output
    +-->

  <xsl:namespace-alias stylesheet-prefix="myxsl" result-prefix="xsl"/>

  <xsl:output method="xml"
    version="1.0" encoding="utf-8" indent="yes" />

<!--+ ==============================================================
    | default templates
    +-->

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*">
    <xsl:element name="{name()}">
      <xsl:apply-templates select="@*|node()" />
    </xsl:element>
  </xsl:template>

  <xsl:template match="xpaths:*">
    <xsl:message terminate="yes">
Unknown or incorrect template instruction <xsl:value-of select="name()" /> within context <xsl:value-of select="name(parent::*)"/>
    </xsl:message>
  </xsl:template>

<!--+ ==============================================================
    | root template
    +-->

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

  <xsl:template match="xpaths:xpaths">
    <myxsl:stylesheet version="1.0">

      <xsl:for-each select="namespace::*[not(name() = 'xpaths')]">
        <xsl:copy />
      </xsl:for-each>

      <myxsl:output method="xml"
        version="1.0" encoding="utf-8" indent="yes" />

      <myxsl:template match="/|@*|node()">
        <myxsl:copy>
          <myxsl:apply-templates select="." mode="xpath1"/>
        </myxsl:copy>
      </myxsl:template>

      <xsl:apply-templates select="xpaths:xpath" />

      <myxsl:template match="/|@*|node()" mode="xpath{count(xpaths:xpath) + 1}">
        <myxsl:apply-templates select="@*|node()" />
      </myxsl:template>
    </myxsl:stylesheet>
  </xsl:template>

  <xsl:template match="xpaths:xpath">
    <!-- default copying -->
    <myxsl:template match="/|@*|node()" mode="xpath{position()}">
      <myxsl:apply-templates select="." mode="xpath{position() + 1}"/>
    </myxsl:template>

    <!-- special case -->
    <myxsl:template match="[EMAIL PROTECTED]" mode="xpath{position()}">
      <xsl:apply-templates select="node()" />
      <myxsl:apply-templates select="." mode="xpath{position() + 1}"/>
    </myxsl:template>
  </xsl:template>

  <xsl:template match="xpaths:literal">
    <xsl:apply-templates select="node()" />
  </xsl:template>

</xsl:stylesheet>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to