Re: [xsl] XSLT problem

Subject: Re: [xsl] XSLT problem
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Mon, 18 Aug 2008 15:46:30 +0200
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/

Current Thread