xsl-list
[Top] [All Lists]

[xsl] Transform help

2017-06-27 11:51:43
I have an XML file with the following format:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi";>
    <Fragment>
        <DirectoryRef Id="WIXUI_INSTALLDIR">
            <Component Id="cmpD21EA675EFA6996C0BC35D1EBF6D2457" Guid="*">
                <File Id="fil23AD96741A175261995FF2E150D0D117" KeyPath="yes" 
Source="$(var.SomeVar)\Bar.exe" />
            </Component>
            <Component Id="cmp4CFE705322C198BF47866FF19D0186CC" Guid="*">
                <File Id="fil75F8456D557F48D20C117E74D90A6065" KeyPath="yes" 
Source="$(var.SomeVar)\Baz.exe" />
            </Component>
            <Component Id="cmp90C9500BC764786BCBA4DD0D0E134F54" Guid="*">
                <File Id="fil2DB44905B644507065B8C7C6B97B2A02" KeyPath="yes" 
Source="$(var.SomeVar)\Foo.exe" />
            </Component>
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="ComponentGroup.Service">
            <ComponentRef Id="cmpD21EA675EFA6996C0BC35D1EBF6D2457" />
            <ComponentRef Id="cmp4CFE705322C198BF47866FF19D0186CC" />
            <ComponentRef Id="cmp90C9500BC764786BCBA4DD0D0E134F54" />
        </ComponentGroup>
    </Fragment>
</Wix>

I need to apply a transform to re-order the DirectoryRef child elements such
that Component/File[@Source="$(var.SomeVar)\Foo.exe"] appears first.

I am not really clear on the semantics of template and copy actions as well
as template specificity. The following omits the outer Component elements
from the File elements;

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:wix="http://schemas.microsoft.com/wix/2006/wi";
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                exclude-result-prefixes="msxsl">
  <xsl:output encoding="UTF-8" indent="yes" method="xml" />

 <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="//wix:DirectoryRef[@Id = 'WIXUI_INSTALLDIR']">
    <xsl:copy>
        <xsl:apply-templates select="@*" />
        <xsl:apply-templates select="//wix:Component/wix:File[@Id = 
'$(var.SomeVar)\Foo.exe']" />
        <xsl:apply-templates select="//wix:Component/wix:File[@Id != 
'$(var.SomeVar)\Foo.exe']" />
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Any idea what I am missing?

Thanks,
jlc
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>