[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Transform help

Subject: Re: Transform help
From: "Terry Badger terry_badger@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 27 Jun 2017 18:25:29 -0000
Re:  Transform help
This should do it. You need the 2 copyall templates from Ken Holman then your template that does special processing of the parent of the elements you want to change their order within the parent. I was a bit lazy and added this to the root of the style sheet 
xpath-default-namespace="http://schemas.microsoft.com/wix/2006/wi"
<?xml version="1.0"?>
<xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/Transform"version="2.0"xpath-default-namespace="http://schemas.microsoft.com/wix/2006/wi">
<xsl:outputencoding="utf-8"indent="yes"/>
<xsl:strip-spaceelements="*"/>
<!-- ==========================================================================-->
<!-- start at root and output a result document to make it easier to see -->
<xsl:templatematch="/">
<xsl:variablename="file-name"select="subsequence(reverse(tokenize(document-uri(.), '/')), 1, 1)"/>
<xsl:result-documenthref="{concat('../out/' , $file-name)}">
<xsl:apply-templates/>
</xsl:result-document>
</xsl:template>
<!-- ==========================================================================-->
<!--use the following to copy all of the content of a node-->
<xsl:templatename="copy-content">
<xsl:apply-templatesselect="@* | processing-instruction() | comment() | * | text() | root"/>
</xsl:template>
<!-- ==========================================================================-->
<!--default behaviours for all nodes-->
<xsl:templatematch="processing-instruction() | comment() | * | @* | text()">
<xsl:copy>
<xsl:call-templatename="copy-content"/>
</xsl:copy>
</xsl:template>
<!-- ==========================================================================-->
<!-- pick the parent element where we want to change the order of the children-->
<xsl:templatematch="DirectoryRef">
<xsl:copy>
<xsl:copy-ofselect="@*"/>
<xsl:apply-templatesselect="Component[contains(File/@Source, 'Foo')]"/>
<xsl:apply-templatesselect="Component[not(contains(File/@Source, 'Foo'))]"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

 
Terry


On Tuesday, June 27, 2017 12:52 PM, "Joseph L. Casale jcasale@xxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:




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 
EasyUnsubscribe (by email) 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.