Its a very interesting way of doing it but I am worried about speed. I had an idea VERY similar to it but am worried about speed. Yours would probably be faster than what i was thinking. I will consider this as an possible solution. Even if it isn't the best solution I could always do this for now and then rewrite it to use <xsl:next-match/> when xalan supports it.(I am pretty currently doesn't but it might...)

I do not know much about STX but I am sure it can be used to solve the problem -- and it would be faster. The only issue I have with that solution is that I am pretty sure its 'xpaths' (stxpaths) are a dumbed down version of xpaths that do not have stuff like preceeding-sibilings.

David


Geert Josten wrote:
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