This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Key and next attribute ?
- To: xsl-list at mulberrytech dot com
- Subject: Key and next attribute ?
- From: Jukka dot T dot Lehtinen at nokia dot com
- Date: Fri, 20 Oct 2000 11:51:02 +0300
- Reply-To: xsl-list at mulberrytech dot com
Hi all !
This time it's key problem...
I want search if thing/@name = graphic/@source and replace graphic/@source
to thing/@sys-id. See my example:
I have source xml file:
-----------------source
<thing name="pu001923431x0xen" sys-id="temp/pu00192784x1x0xen.gif" />
<thing name="pu00222575x1x0xsw" sys-id="temp/pu00222575x1x0xsw.gif" /> <!--
this sould match -->
<thing name="pu00192784x1x0xen" sys-id="temp/pu00192784x1x0xen.gif" /> <!--
this sould match -->
<thing name="pu00342784x1x0xen" sys-id="temp/pu00192784x1x0xen.gif" />
<graphic source="pu00222575x1x0xsw"/>
<graphic source="pu00192803x1x0xen"/>
<graphic source="pu00192803x1x0xdo.gif"/>
----------------source
and I want to match that <graphic> element and check if tin thing/@name is
same.. to get that filepath (temp/pu00222575x1x0xsw.gif ,ok now it looks
like almoust same like that @source, but it can be anything) and put it in
@source attribute...
----------------wanted result
<graphic source="temp/pu00222575x1x0xsw.gif"/> <!-- @source matched and
taken from @sys-id -->
<graphic source="temp/pu00192803x1x0xen.gif"/>
<graphic source="pu00192803x1x0xdo.gif"/>
----------------wanted result
this is what i have tried:
----------------------------XSLT
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
encoding="UTF-8"
media-type="text/xml" />
<xsl:key name="thingsearch" match="thing/@name" use="."/>
<xsl:template match="graphic">
<graphic>
<xsl:choose>
<xsl:when test="contains(@source, '.gif')">
<xsl:attribute name="source"><xsl:value-of
select="@source" /></xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="source"><xsl:value-of
select="key('thingsearch', @source)" /></xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</graphic>
</xsl:template>
</xsl:stylesheet>
----------------------------XSLT
MY PROBLEM: How should 'use="??"' used, so that it puts thing/@sys-id to
that graphic/@source attribute. Now currently it puts there itselfs ".". I
have tried 'use="@sys-id"', 'use="thing/@sys-id"', ... But is it possible to
move from attribute to the next attribute ??
There may be some other solutins than use key, but with key, it could be
quite easy.
Thanks in advandce....
Cheerzz...
Jukka Lehtinen
Jukka.t.lehtinen@nokia.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list