-
Notifications
You must be signed in to change notification settings - Fork 0
/
unattend2cmd.xsl
63 lines (61 loc) · 3.29 KB
/
unattend2cmd.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:u="urn:schemas-microsoft-com:unattend">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<!-- from https://www.oreilly.com/library/view/xslt-cookbook/0596003722/ch01s07.html -->
<xsl:template name="search-and-replace-whole-words-only">
<xsl:param name="input"/>
<xsl:param name="search-string"/>
<xsl:param name="replace-string"/>
<xsl:choose>
<!-- See if the input contains the search string -->
<xsl:when test="contains($input,$search-string)">
<!-- If so, then test that the before and after characters are word
delimiters. -->
<xsl:variable name="before"
select="substring-before($input,$search-string)"/>
<xsl:variable name="before-char"
select="substring(concat(' ',$before),string-length($before) +1, 1)"/>
<xsl:variable name="after"
select="substring-after($input,$search-string)"/>
<xsl:variable name="after-char"
select="substring($after,1,1)"/>
<xsl:value-of select="$before"/>
<xsl:choose>
<xsl:when test="not(normalize-space($before-char)) and
not(normalize-space($after-char))">
<xsl:value-of select="$replace-string"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$search-string"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="search-and-replace-whole-words-only">
<xsl:with-param name="input" select="$after"/>
<xsl:with-param name="search-string" select="$search-string"/>
<xsl:with-param name="replace-string" select="$replace-string"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- There are no more occurences of the search string so
just return the current input string -->
<xsl:value-of select="$input"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/u:unattend">
<xsl:for-each select="u:settings[@pass='specialize']/u:component[@name='Microsoft-Windows-Deployment']/u:RunSynchronous/u:RunSynchronousCommand">
<xsl:sort select="u:Order" data-type="number" />
<xsl:call-template name="search-and-replace-whole-words-only">
<xsl:with-param name="input" select="u:Path" />
<xsl:with-param name="search-string">%i</xsl:with-param>
<xsl:with-param name="replace-string">%%i</xsl:with-param>
</xsl:call-template>
<xsl:text>
</xsl:text>
</xsl:for-each>
<xsl:for-each select="u:settings[@pass='oobeSystem']/u:component[@name='Microsoft-Windows-Shell-Setup']/u:FirstLogonCommands/u:SynchronousCommand">
<xsl:sort select="u:Order" data-type="number" />
<xsl:value-of select="u:CommandLine" />
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>