xsl-list
[Top] [All Lists]

Re: [xsl] XSLT problem

2008-08-18 06:46:58
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>
--~--