Fantastic. :)
It works with the examples I have provided you.
But I should have said in first place that the <UnitArtInfo> can have
more than 3 sub elements.
1) So I wish to copy all the rest elements between <UnitArtInfo> and
</UnitArtInfo> that could be there, inclusive this functionality that
you have already successfully implemented (Button). I tried to change
your code to <xsl:apply-templates select="@* | node()"/> but still
didn't succeed.
2) All other Elements that do not match the list (e.g. Lion) should only
be copied over in the output like Zeppelin, but without a <Button>
Element.
New Expected Output:
<Civ4ArtDefines xmlns="x-schema:CIV4ArtDefinesSchema.xml">
<UnitArtInfos>
<UnitArtInfo>
<Type>ART_DEF_UNIT_LION</Type>
<fScale>0.61</fScale>
</UnitArtInfo>
<UnitArtInfo>
<Type>ART_DEF_UNIT_ZEPPELIN</Type>
<Button>Art/Interface/Buttons/Units/Zeppelin.dds</Button>
<fScale>0.70</fScale>
</UnitArtInfo>
</UnitArtInfos>
</Civ4ArtDefines>
Would that be possible?
Many Thanks,
Houman
-----Original Message-----
From: Martin Honnen [mailto:Martin(_dot_)Honnen(_at_)gmx(_dot_)de]
Sent: 18 August 2008 14:47
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] XSLT problem
Houman Khorasani wrote:
Expected Output XML:
<Civ4ArtDefines xmlns="x-schema:CIV4ArtDefinesSchema.xml">
<UnitArtInfos>
<UnitArtInfo>
<Type>ART_DEF_UNIT_ZEPPELIN</Type>
<Button>Art/Interface/Buttons/Units/Zeppelin.dds</Button>
<fScale>0.70</fScale>
</UnitArtInfo>
</UnitArtInfos>
</Civ4ArtDefines>
The following stylesheet produces the output you have listed above:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="x-schema:CIV4ArtDefinesSchema.xml"
xmlns:a="x-schema:CIV4ArtDefinesSchema.xml"
exclude-result-prefixes="a"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="unitInfo"
select="document('')/xsl:stylesheet/a:UnitInfos/a:Unit"/>
<UnitInfos xmlns="x-schema:CIV4ArtDefinesSchema.xml">
<Unit>
<Type>ART_DEF_UNIT_ZEPPELIN</Type>
<Button>Art/Interface/Buttons/Units/Zeppelin.dds</Button>
</Unit>
</UnitInfos>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="a:UnitArtInfo[a:Type =
document('')/xsl:stylesheet/a:UnitInfos/a:Unit/a:Type]">
<xsl:copy>
<xsl:apply-templates select="@* | a:Type"/>
<xsl:element name="Button">
<xsl:value-of select="$unitInfo[a:Type =
current()/a:Type]/a:Button"/>
</xsl:element>
<xsl:apply-templates select="a:fScale"/>
</xsl:copy>
</xsl:template>
<xsl:template match="a:UnitArtInfo[not(a:Type =
document('')/xsl:stylesheet/a:UnitInfos/a:Unit/a:Type)]"/>
</xsl:stylesheet>
That assumes you want to process those UnitArtInfo elements for which
the Type is listed in the stylesheet data.
--
Martin Honnen
http://JavaScript.FAQTs.com/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed. If
you have received this email in error please notify the system manager. This
message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--