Try:
<div id="{ concat(@id, generate-id(self::*[not(@id and
string(@id))]))}">Div Text</div>
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="div">
<div id="{ concat(@id, generate-id(self::*[not(@id and
string(@id))]))}">Div Text</div>
</xsl:template>
</xsl:stylesheet>
when applied on this source.xml:
<t>
<div id="1">xxx</div>
<div id="">yyy</div>
<div>zzz</div>
</t>
produces the wanted result:
<?xml version="1.0" encoding="UTF-16"?>
<div id="1">Div Text</div>
<div id="IDAJA2S">Div Text</div>
<div id="IDANA2S">Div Text</div>
Hope this helped.
=====
Cheers,
Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
"Vince C." <no**@hotmail.com> wrote in message
news:3f*********************@read.news.be.uu.net.. .
Hi, all.
I'd like to know if there's a way to simplify writing attribute values in
XSLT. The case is the following:
<xsl:template ...>
<div id="{ if (@id) @id else generate-id() }">Div Text</div>
</xsl:template>
If context node has an @id then I want that id for output. Otherwise I
want to generate an id if there is none. I know the "long" method which is:
<xsl:attribute name="id">
<xsl:choose>
<xsl:when test="@id"><xsl:value-of select="@id"/></xsl:when>
<xsl:otherwise><xsl:value-of select="generate-id()"/></xsl:otherwise>
</xsl:choose>
</xsl:attribute>
But it's too long to me. Is there a shortcut? Note as I'm using MSXML4 I
can use MS XSL extensions too.
Thanks for any hint/suggestion,
Vince C.