This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Usefull?


Hi,

I think this cuold be usefull for someone else, basicly only add id to every
element from the XML file an unique ID.

<?xml version='1.0' encoding='ISO-8859-1'?>
<xsl:stylesheet
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version = "1.0">
  <xsl:output method="xml" encoding="ISO-8859-1" indent="yes" />

  <xsl:template match = "*" >
    <xsl:copy >
      <xsl:apply-templates select = "@*" />
      <xsl:attribute
      	   name="id"><xsl:call-template name="object.id"/></xsl:attribute>
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>

  <xsl:template match = "@*" >
    <xsl:copy />
  </xsl:template>

  <!--
====================================================================== -->

  <xsl:template name="object.id">
    <xsl:param name="object" select="."/>
    <xsl:choose>
      <xsl:when test="$object/@id">
        <xsl:value-of select="$object/@id"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="generate-id($object)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

Regards,
Fernando López Carballeda

PS.- Do not hesitate to correct me.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]