XML/XSL Portal

Multiple Stylesheet Aware
HideXML SlideshowHide
     
  
 
 

The following feeds are currently available for adding to your navigation bar.

+ Bayes.Co.UK
Bayes.Co.UK http://www.rssboard.org/rss-specification BlogEngine.NET 3.2.0.3 http://www.bayes.co.uk/blog/opml.axd http://www.dotnetblogengine.net/syndication.axd Chris Bayes Bayes.Co.UK 0.000000 0.000000

Powershell Translet XQuery T-DAXmlToWpl

<p>There is no reason why a Translet shouldn't use XQuery as opposed to Xslt. So here is one that will transform a DAXml into a Windows Play List (WPL) using XQuery. It is quite simple</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:8b2f0677-5119-4638-80a2-d4cd8b38fc64" class="wlWriterSmartContent"><div class='highlightbackground'> <span class='keyword'>function</span>&nbsp;<span class='commandarg'>T-DAXmlToWpl</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>param</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$inxml</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>begin</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='command'>Add-Type</span>&nbsp;<span class='commandparam'>-path</span>&nbsp;<span class='string'>"PSLib:\xml\xquery\querymachine\QueryMachine.XQuery.dll"</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xq</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='string'>@'</span><br /> <span class='string'>(:&lt;?wpl&nbsp;version="1.0"?&gt;:)</span><br /> <span class='string'>&lt;smil&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta&nbsp;name="Generator"&nbsp;content="Powershell&nbsp;Translet&nbsp;T-Dax2Wpl"/&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;author&gt;Chris&nbsp;Bayes&lt;/author&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Playlist&lt;/title&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;seq&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><br /> <span class='string'>for&nbsp;$f&nbsp;in&nbsp;//file</span><br /> <span class='string'>return&nbsp;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;media&nbsp;src="{$f/@FullName}"&nbsp;/&gt;</span><br /> <span class='string'></span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/seq&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;</span><br /> <span class='string'>&lt;/smil&gt;</span><br /> <span class='string'>'@</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>process</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>if</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$_</span>&nbsp;<span class='operator'>-is</span>&nbsp;<span class='type'>[xml]</span><span class='foreground'>)</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xqresult</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='type'>[DataEngine.XQuery.XPathFactory]</span><span class='operator'>::</span><span class='foreground'>QuerySingleNode</span><span class='foreground'>(</span><span class='variable'>$_</span><span class='operator'>,</span>&nbsp;<span class='variable'>$xq</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xqresult</span><span class='operator'>.</span><span class='foreground'>OuterXml</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>end</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>if</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$inxml</span>&nbsp;<span class='operator'>-is</span>&nbsp;<span class='type'>[xml]</span><span class='foreground'>)</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xqresult</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='type'>[DataEngine.XQuery.XPathFactory]</span><span class='operator'>::</span><span class='foreground'>QuerySingleNode</span><span class='foreground'>(</span><span class='variable'>$inxml</span><span class='operator'>,</span>&nbsp;<span class='variable'>$xq</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xqresult</span><span class='operator'>.</span><span class='foreground'>OuterXml</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> <span class='foreground'>}</span> </div></div> <p>I am using OuterXml here because the result of the query is a single XmlElement (&lt;smil&gt;). The result of this translet would usually be written to a file with the Set-Content commandlet so it is ok to pass a string down the pipeline. If an [xml] object is required then [xml]($xqresult.OuterXml) can be used instead. I will have to do some timings to see if importing $xqresult into a new emty [xml] object is quicker than casting to an [xml] object.</p> <p>It can be used like this</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:f474cdb7-74f0-4aee-9680-f280e18428d1" class="wlWriterSmartContent"><div class="powershellbackground">PS> . .\T-DAXmlToWpl.ps1<br/> PS> Get-DirAsXml ..\test -props=@{FullName=""} | T-DAXmlToWpl | sc playlist.wpl</div></div> <p></p> <p> After a bit of testing I changed the XQuery to </p> <p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:13a7cdd0-49cf-4022-9276-5386a2d1940b" class="wlWriterSmartContent"><div class='highlightbackground'> &nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xq</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='string'>@'</span><br /> <span class='string'>(:&lt;?wpl&nbsp;version="1.0"?&gt;:)</span><br /> <span class='string'>document{</span><br /> <span class='string'>&lt;smil&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta&nbsp;name="Generator"&nbsp;content="Powershell&nbsp;Translet&nbsp;T-Dax2Wpl"/&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;author&gt;Chris&nbsp;Bayes&lt;/author&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Playlist&lt;/title&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;seq&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><br /> <span class='string'>for&nbsp;$f&nbsp;in&nbsp;//file</span><br /> <span class='string'>return</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;media&nbsp;src="{$f/@FullName}"&nbsp;/&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/seq&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;</span><br /> <span class='string'>&lt;/smil&gt;</span><br /> <span class='string'>}</span><br /> <span class='string'>'@</span> </div></div></p> <p>and QuerySingleNode returns an XmlDocument :-) however it has a &lt;?xml version="1.0" encoding="utf-8"?&gt; xml declaration which is not part of the SMIL spec but Windows Media Player doesn't seem to mind.</p> <p>I then tried </p> <p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:c2bf7cd1-cd76-426d-bf93-ec4d251e1c4f" class="wlWriterSmartContent"><div class='highlightbackground'> <span class='keyword'>function</span>&nbsp;<span class='commandarg'>T-DAXmlToWpl</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>param</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$inxml</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>begin</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='command'>Add-Type</span>&nbsp;<span class='commandparam'>-path</span>&nbsp;<span class='string'>"PSLib:\xml\xquery\querymachine\QueryMachine.XQuery.dll"</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xq</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='string'>@'</span><br /> <span class='string'>document{</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;?wpl&nbsp;version="1.0"?&gt;,&lt;smil&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;head&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;meta&nbsp;name="Generator"&nbsp;content="Powershell&nbsp;Translet&nbsp;T-DAXmlToWpl"/&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;author&gt;Chris&nbsp;Bayes&lt;/author&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Playlist&lt;/title&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/head&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;body&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;seq&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;$f&nbsp;in&nbsp;//file[@Extension=".mp3"]</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;media&nbsp;src="{$f/@FullName}"&nbsp;/&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/seq&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/body&gt;</span><br /> <span class='string'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;/smil&gt;</span><br /> <span class='string'>}</span><br /> <span class='string'>'@</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>process</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>if</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$_</span>&nbsp;<span class='operator'>-is</span>&nbsp;<span class='type'>[xml]</span><span class='foreground'>)</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>[DataEngine.XQuery.XPathFactory]</span><span class='operator'>::</span><span class='foreground'>QuerySingleNode</span><span class='foreground'>(</span><span class='variable'>$_</span><span class='operator'>,</span>&nbsp;<span class='variable'>$xq</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>end</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>if</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$inxml</span>&nbsp;<span class='operator'>-is</span>&nbsp;<span class='type'>[xml]</span><span class='foreground'>)</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>[DataEngine.XQuery.XPathFactory]</span><span class='operator'>::</span><span class='foreground'>QuerySingleNode</span><span class='foreground'>(</span><span class='variable'>$inxml</span><span class='operator'>,</span>&nbsp;<span class='variable'>$xq</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> <span class='foreground'>}</span> </div></div></p> <p>which produces something like this</p> <p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:48176bfe-ba9b-4ad8-bde5-29661bc19770" class="wlWriterSmartContent"><div class="highlightbackground"><div class="xml"> &lt;?<span class="piname">xml</span> <span class="pitext">version="1.0"</span> <span class="pitext">encoding="utf-8"</span>?&gt;<br> &lt;?<span class="piname">wpl</span> <span class="pitext">version="1.0"</span>?&gt;<br> &lt;<span class="element">smil</span>&gt;<span class="text"><br>     </span>&lt;<span class="element">head</span>&gt;<span class="text"><br>         </span>&lt;<span class="element">meta</span> <span class="attribute">name</span>="<span class="attributetext">Generator</span>" <span class="attribute">content</span>="<span class="attributetext">Powershell Translet T-DAXmlToWpl</span>" /&gt;<span class="text"><br>         </span>&lt;<span class="element">author</span>&gt;<span class="text">Chris Bayes</span>&lt;/<span class="element">author</span>&gt;<span class="text"><br>         </span>&lt;<span class="element">title</span>&gt;<span class="text">Playlist</span>&lt;/<span class="element">title</span>&gt;<span class="text"><br>     </span>&lt;/<span class="element">head</span>&gt;<span class="text"><br>     </span>&lt;<span class="element">body</span>&gt;<span class="text"><br>         </span>&lt;<span class="element">seq</span>&gt;<span class="text"><br>             </span>&lt;<span class="element">media</span> <span class="attribute">src</span>="<span class="attributetext">D:\music\Culture - Two Sevens Clash (30th Anniversary Ed.) TQMP\04_Culture - Two Sevens Clash.mp3</span>" /&gt;<span class="text"><br>             ...<br>         </span>&lt;/<span class="element">seq</span>&gt;<span class="text"><br>     </span>&lt;/<span class="element">body</span>&gt;<span class="text"><br> </span>&lt;/<span class="element">smil</span>&gt;<br> </div> </div></div></p> <p>which has the xml declaration and the wpl processing instruction which Windows Media Player also plays so I will leave it like that. </p> <p>Because we are producing an XmlDocument we need to use the Format-Xml commandlet before we can use the Set-Content commandlet, something like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:fde1584c-a30e-4368-9238-b224748ab9d4" class="wlWriterSmartContent"><div class="powershellbackground">PS> Get-DirAsXml D:\music -props @{FullName="";Extension=""} | T-DAXmlToWpl | Format-Xml | Set-Content allplaylist.wpl </div></div>
http://www.bayes.co.uk/blog/post/Powershell-Translet-XQuery-T-DAXmlToWpl.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=0fd1bb9c-5777-4977-9dd3-a7bfeeb87d6a Sat, 6 Feb 2010 18:36:05 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=0fd1bb9c-5777-4977-9dd3-a7bfeeb87d6a 24 http://www.bayes.co.uk/blog/trackback.axd?id=0fd1bb9c-5777-4977-9dd3-a7bfeeb87d6a http://www.bayes.co.uk/blog/post/Powershell-Translet-XQuery-T-DAXmlToWpl.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=0fd1bb9c-5777-4977-9dd3-a7bfeeb87d6a

Powershell DAXml Xaml XQuery Explorer.

<p>I recently spotted <a href="http://qm.codeplex.com/" target="_blank">Standalone XQuery Implementation in .NET</a> on Codeplex and decided to integrate it with DAXml explorer.</p> <p>I'm going to start with a <a href="http://www.bayes.co.uk/blog/post/Powershell-Xml-Folder-Tree-Xaml-Explorer.aspx" target="_blank">previous post</a> and add a few things. A ToolBar to switch to XQuery search and run the XQuery</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:8fc38857-fa99-40ea-8dc7-862f106c7946" class="wlWriterSmartContent"><div class="highlightbackground"><div class="xml">&lt;<span class="element">ToolBarTray</span> <span class="attribute">Background</span>="<span class="attributetext">White</span>" <span class="attribute">Grid.Row</span>="<span class="attributetext">0</span>"&gt;<span class="text"><br>     </span>&lt;<span class="element">ToolBar</span> <span class="attribute">Band</span>="<span class="attributetext">1</span>" <span class="attribute">BandIndex</span>="<span class="attributetext">0</span>"&gt;<span class="text"><br>         </span>&lt;<span class="element">Button</span> <span class="attribute">Name</span>="<span class="attributetext">SEARCHTOOL</span>"&gt;<span class="text"><br>             </span>&lt;<span class="element">TextBlock</span>&gt;<span class="text">Search</span>&lt;/<span class="element">TextBlock</span>&gt;<span class="text"><br>         </span>&lt;/<span class="element">Button</span>&gt;<span class="text"><br>         </span>&lt;<span class="element">Button</span> <span class="attribute">Name</span>="<span class="attributetext">RUNTOOL</span>"&gt;<span class="text"><br>             </span>&lt;<span class="element">TextBlock</span>&gt;<span class="text">Run</span>&lt;/<span class="element">TextBlock</span>&gt;<span class="text"><br>         </span>&lt;/<span class="element">Button</span>&gt;<span class="text"><br>     </span>&lt;/<span class="element">ToolBar</span>&gt;<span class="text"><br>     </span>&lt;<span class="element">ToolBar</span> <span class="attribute">Band</span>="<span class="attributetext">1</span>" <span class="attribute">BandIndex</span>="<span class="attributetext">1</span>" <span class="attribute">Visibility</span>="<span class="attributetext">{Binding ElementName=TABCONTROL, Path=Visibility}</span>"&gt;<span class="text"><br>         </span>&lt;<span class="element">TextBlock</span> <span class="attribute">FontSize</span>="<span class="attributetext">20</span>"&gt;<span class="text"> A </span>&lt;/<span class="element">TextBlock</span>&gt;<span class="text"><br>         </span>&lt;<span class="element">Slider</span> <span class="attribute">Name</span>="<span class="attributetext">TEXTSIZE</span>" <span class="attribute">Maximum</span>="<span class="attributetext">50</span>" <span class="attribute">Width</span>="<span class="attributetext">100</span>" <span class="attribute">Value</span>="<span class="attributetext">12</span>" <span class="attribute">Orientation</span>="<span class="attributetext">Horizontal</span>" <span class="attribute">HorizontalAlignment</span>="<span class="attributetext">Left</span>" <span class="attribute">AutoToolTipPlacement</span>="<span class="attributetext">BottomRight</span>" <span class="attribute">AutoToolTipPrecision</span>="<span class="attributetext">2</span>" /&gt;<span class="text"><br>     </span>&lt;/<span class="element">ToolBar</span>&gt;<span class="text"><br> </span>&lt;/<span class="element">ToolBarTray</span>&gt;<br> </div> </div></div> <p></p> <p>and a TabControl to switch between the XQuery and the results</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:862756dd-f5d2-47ed-a930-b5de8c170de9" class="wlWriterSmartContent"><div class="highlightbackground"><div class="xml">&lt;<span class="element">TabControl</span> <span class="attribute">Name</span>="<span class="attributetext">TABCONTROL</span>" <span class="attribute">Grid.Column</span>="<span class="attributetext">2</span>" <span class="attribute">Grid.Row</span>="<span class="attributetext">1</span>" <span class="attribute">Visibility</span>="<span class="attributetext">Hidden</span>"&gt;<span class="text"><br>     </span>&lt;<span class="element">TabItem</span> <span class="attribute">Name</span>="<span class="attributetext">TABXQUERY</span>" <span class="attribute">Header</span>="<span class="attributetext">XQuery</span>"&gt;<span class="text"><br>         </span>&lt;<span class="element">TabItem.Content</span>&gt;<span class="text"><br>             </span>&lt;<span class="element">TextBox</span> <span class="attribute">Name</span>="<span class="attributetext">TABQUERYSOURCE</span>" <span class="attribute">AcceptsReturn</span>="<span class="attributetext">True</span>" <span class="attribute">VerticalScrollBarVisibility</span>="<span class="attributetext">Auto</span>" <span class="attribute">HorizontalScrollBarVisibility</span>="<span class="attributetext">Auto</span>" <span class="attribute">FontSize</span>="<span class="attributetext">{Binding ElementName=TEXTSIZE, Path=Value}</span>" /&gt;<span class="text"><br>         </span>&lt;/<span class="element">TabItem.Content</span>&gt;<span class="text"><br>     </span>&lt;/<span class="element">TabItem</span>&gt;<span class="text"><br>     </span>&lt;<span class="element">TabItem</span> <span class="attribute">Name</span>="<span class="attributetext">XQUERYRESULT</span>" <span class="attribute">Header</span>="<span class="attributetext">Result</span>"&gt;<span class="text"><br>         </span>&lt;<span class="element">TabItem.Content</span>&gt;<span class="text"><br>             </span>&lt;<span class="element">ListView</span> <span class="attribute">Name</span>="<span class="attributetext">LISTVIEW2</span>" <span class="attribute">Grid.Column</span>="<span class="attributetext">2</span>" <span class="attribute">Grid.Row</span>="<span class="attributetext">1</span>" <span class="attribute">HorizontalAlignment</span>="<span class="attributetext">Stretch</span>" <span class="attribute">Visibility</span>="<span class="attributetext">Visible</span>"&gt;<span class="text"><br>                 </span>&lt;<span class="element">ListView.View</span>&gt;<span class="text"><br>                     </span>&lt;<span class="element">GridView</span> <span class="attribute">AllowsColumnReorder</span>="<span class="attributetext">true</span>" <span class="attribute">ColumnHeaderContainerStyle</span>="<span class="attributetext">{DynamicResource CustomHeaderStyle}</span>"&gt;<span class="text"><br>                         </span>&lt;<span class="element">GridViewColumn</span> <span class="attribute">Header</span>="<span class="attributetext">Name</span>" <span class="attribute">CellTemplate</span>="<span class="attributetext">{StaticResource ItemTemplate}</span>"&gt;<span class="text"><br>                         </span>&lt;/<span class="element">GridViewColumn</span>&gt;<span class="text"><br>                     </span>&lt;/<span class="element">GridView</span>&gt;<span class="text"><br>                 </span>&lt;/<span class="element">ListView.View</span>&gt;<span class="text"><br>             </span>&lt;/<span class="element">ListView</span>&gt;<span class="text"><br>         </span>&lt;/<span class="element">TabItem.Content</span>&gt;<span class="text"><br>     </span>&lt;/<span class="element">TabItem</span>&gt;<span class="text"><br> </span>&lt;/<span class="element">TabControl</span>&gt;<br> </div> </div></div> <p></p> <p>We need a couple of events wired up</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:f4e667c3-540b-4488-bd18-249f876c6530" class="wlWriterSmartContent"><div class='highlightbackground'> <span class='variable'>$SEARCHTOOL</span><span class='operator'>.</span><span class='foreground'>add_Click</span><span class='foreground'>(</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>if</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$TABCONTROL</span><span class='operator'>.</span><span class='foreground'>Visibility</span>&nbsp;<span class='operator'>-eq</span>&nbsp;<span class='type'>[System.Windows.Visibility]</span><span class='operator'>::</span><span class='foreground'>Visible</span><span class='foreground'>)</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$TABCONTROL</span><span class='operator'>.</span><span class='foreground'>Visibility</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='type'>[System.Windows.Visibility]</span><span class='operator'>::</span><span class='foreground'>Hidden</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$LISTVIEW</span><span class='operator'>.</span><span class='foreground'>Visibility</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='type'>[System.Windows.Visibility]</span><span class='operator'>::</span><span class='foreground'>Visible</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><span class='keyword'>else</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$TABCONTROL</span><span class='operator'>.</span><span class='foreground'>Visibility</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='type'>[System.Windows.Visibility]</span><span class='operator'>::</span><span class='foreground'>Visible</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$LISTVIEW</span><span class='operator'>.</span><span class='foreground'>Visibility</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='type'>[System.Windows.Visibility]</span><span class='operator'>::</span><span class='foreground'>Hidden</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><br /> <span class='foreground'>}</span><span class='foreground'>)</span><br /> </div></div> <p></p> <p>that will switch from normal to search view. And an event to do the XQuery on the DAXml</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:59797c9b-9a2c-459e-a1e7-ae2855bb4f78" class="wlWriterSmartContent"><div class='highlightbackground'> <span class='variable'>$RUNTOOL</span><span class='operator'>.</span><span class='foreground'>add_Click</span><span class='foreground'>(</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='command'>Add-Type</span>&nbsp;<span class='commandparam'>-path</span>&nbsp;<span class='string'>"D:\QueryMachine.XQuery.1.3\QueryMachine.XQuery.1.3\QueryMachine.XQuery.dll"</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xqresult</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='type'>[DataEngine.XQuery.XPathFactory]</span><span class='operator'>::</span><span class='foreground'>QueryNodes</span><span class='foreground'>(</span><span class='variable'>$xml</span><span class='operator'>,</span>&nbsp;<span class='variable'>$TABQUERYSOURCE</span><span class='operator'>.</span><span class='foreground'>Text</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$LISTVIEW2</span><span class='operator'>.</span><span class='foreground'>ItemsSource</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='variable'>$xqresult</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$TABXQUERYRESULT</span><span class='operator'>.</span><span class='foreground'>IsSelected</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='variable'>$true</span><br /> <span class='foreground'>}</span><span class='foreground'>)</span> </div> </div> <p>This might be displayed like this</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpXQueryV1.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExpXQueryV1" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpXQueryV1_thumb.jpg" width="244" height="86"></a> <br>Normal explorer view.</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpXQueryV2.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExpXQueryV2" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpXQueryV2_thumb.jpg" width="244" height="86"></a> <br>XQuery search view.</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpXQueryV3.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExpXQueryV3" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpXQueryV3_thumb.jpg" width="244" height="86"></a> <br>XQuery result view.</p> <p>It can be used like this</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:550d1589-3f00-473e-aa16-9ea99b692d06" class="wlWriterSmartContent"><div class="powershellbackground">Xaml-DisplayDirExp (get-dirasxml ..\test -props @{Length="";LastWriteTime="";Extension="";FullName=""} )</div></div> <p></p> <p>or like this</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:95dcda49-4a06-49d2-93c0-3d416848fe77" class="wlWriterSmartContent"><div class='highlightbackground'> <span class='command'>Xaml-DisplayDirExp</span>&nbsp;<span class='foreground'>(</span><span class='command'>get-dirasxml</span>&nbsp;<span class='commandarg'>..\test</span>&nbsp;<span class='commandparam'>-CustomProps</span>&nbsp;<span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>param</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$element</span><span class='operator'>,</span>&nbsp;<span class='variable'>$directory</span><span class='operator'>,</span>&nbsp;<span class='variable'>$file</span><span class='operator'>,</span>&nbsp;<span class='variable'>$prefix</span><span class='operator'>,</span>&nbsp;<span class='variable'>$namespace</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>try</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>[xml]</span><span class='variable'>$xmp</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='foreground'>(</span><span class='command'>pslib:\xml\ReadingXMP.exe</span>&nbsp;<span class='variable'>$file</span><span class='operator'>.</span><span class='foreground'>FullName</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xmpr</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='variable'>$xmp</span><span class='operator'>.</span><span class='foreground'>SelectSingleNode</span><span class='foreground'>(</span><span class='string'>"/*"</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$inode</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='variable'>$element</span><span class='operator'>.</span><span class='foreground'>OwnerDocument</span><span class='operator'>.</span><span class='foreground'>ImportNode</span><span class='foreground'>(</span><span class='variable'>$xmpr</span><span class='operator'>,</span>&nbsp;<span class='variable'>$true</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>[void]</span><span class='variable'>$element</span><span class='operator'>.</span><span class='foreground'>AppendChild</span><span class='foreground'>(</span><span class='variable'>$inode</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><span class='keyword'>catch</span><span class='foreground'>{</span><span class='foreground'>}</span><br /> <span class='foreground'>}</span>&nbsp;<span class='commandparam'>-props</span>&nbsp;<span class='foreground'>@{</span><span class='foreground'>Length</span><span class='operator'>=</span><span class='string'>""</span><span class='statementsep'>;</span><span class='foreground'>LastWriteTime</span><span class='operator'>=</span><span class='string'>""</span><span class='statementsep'>;</span><span class='foreground'>Extension</span><span class='operator'>=</span><span class='string'>""</span><span class='statementsep'>;</span><span class='foreground'>FullName</span><span class='operator'>=</span><span class='string'>""</span><span class='foreground'>}</span>&nbsp;<span class='foreground'>)</span><br /> </div></div> <p></p> <p>which will use the ReadingXMP from this <a href="http://www.bayes.co.uk/blog/post/XMP-Getting-Raw-XMP-RDF-Using-Adobe-XMP-Toolkit.aspx" target="_blank">previous post</a> to stuff XMP RDF from JPG files into the DAXml.</p> <p>Depending on which method you use will depend on the XQuery you use. With DAXml stuffing you can use an XQuery like this</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:f82638fa-6838-4c24-ad70-2e1fc622b3c6" class="wlWriterSmartContent"><!-- --> <div class="highlightbackground">declare namespace MPReg="http://ns.microsoft.com/photo/1.2/t/Region#";<br/> <br/> for $a in //file[@Extension=".jpg"][//MPReg:PersonDisplayName = "Chris Bayes"]<br/> order by $a/@Length<br/> return $a<br/></div></div> <p></p> <p>and if you use sidecar files then you can use XQuery like this</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:acd8e24d-ca4c-4afe-8fe3-9eaab88fc88b" class="wlWriterSmartContent"><!-- --> <div class="highlightbackground">declare namespace MPReg="http://ns.microsoft.com/photo/1.2/t/Region#";<br/> <br/> for $a in //file[@Extension=".jpg"]<br/> where doc(concat(@FullName, ".xmp"))//MPReg:PersonDisplayName = "Chris Bayes"<br/> order by $a/@Length<br/> return $a<br/></div></div> <p></p> <p>either way the XQuery will return all JPG files in all your folders where 'Chris Bayes' is in the MPReg:PersonDisplayName of the XMP RDF ordered by the file size.</p> <p>If you used order by $a//exif:GPSLatitude you would get all JPG files in all your folders where 'Chris Bayes' is in the MPReg:PersonDisplayName of the XMP RDF ordered by the e/w distance from the Greenwich Meridian. </p> <p>Here is the code </p> <p><a title="Xaml-DisplayDirExpXQuerySearch.zip" href="http://www.bayes.co.uk/blog/file.axd?file=2010%2f01%2fXaml-DisplayDirExpXQuerySearch.zip">Xaml-DisplayDirExpXQuerySearch.zip</a></p>
http://www.bayes.co.uk/blog/post/Powershell-DAXml-Xaml-XQuery-Explorer.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=8d2ecd92-ce0a-4106-b646-2ca20f6966d9 Tue, 26 Jan 2010 12:15:09 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=8d2ecd92-ce0a-4106-b646-2ca20f6966d9 38 http://www.bayes.co.uk/blog/trackback.axd?id=8d2ecd92-ce0a-4106-b646-2ca20f6966d9 http://www.bayes.co.uk/blog/post/Powershell-DAXml-Xaml-XQuery-Explorer.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=8d2ecd92-ce0a-4106-b646-2ca20f6966d9

XMP Getting Raw XMP RDF Using Adobe XMP Toolkit

<p>I wanted to get the raw XMP RDF data from some JPEG files. I looked at Microsoft Windows Imaging Component and although it will get individual metadata properties I couldn't find a way to get the whole XMP RDF packet. I saw some posts about extracting it using a substring aproach by getting all the data between &lt;?xpacket begin='´╗┐' id='some uid'?&gt; and &lt;?xpacket end='w'?&gt; but there can be several RDF packets in a file and it also seems that it can be zipped so it doesn't work so well. </p> <p>I then spotted the <a title="Adobe XMP Toolkit" href="http://www.adobe.com/devnet/xmp/" target="_blank">Adobe XMP Toolkit</a> and this has handlers for about 24 different file types. It is written in C++ and is only provided as source code. However it does have Visual Studio Solution files and can be built with <a title="Visual Studio Express C++" href="http://www.microsoft.com/express/Downloads/" target="_blank">Visual Studio Express C++</a> free edition. So download that. There are a couple of third-party things it needs (expat, zlib, QT) so download those too and put them in the third-party folder as per the ReadMe.txt files.</p> <p>There are some walkthroughs showing how to use the toolkit and the ReadingXMP project is a good place to start. It shows how to read individual properties which is what we don't want so remove all of that properties code and replace it with this</p> <div class="highlightbackground"><pre class="csharpcode"> <span class="kwrd">if</span>(ok) { <span class="rem">// Create the xmp object and get the xmp data</span> SXMPMeta meta; <span class="kwrd">string</span> rawrdf; myFile.GetXMP(&amp;meta, &amp;rawrdf, 0); cout &lt;&lt; rawrdf &lt;&lt; endl; <span class="rem">// Close the SXMPFile. The resource file is already closed if it was</span> <span class="rem">// opened as read only but this call must still be made.</span> myFile.CloseFile(); } <span class="kwrd">else</span> { cout &lt;&lt; <span class="str">"Unable to open "</span> &lt;&lt; filename &lt;&lt; endl; }</pre></div> <p>In case you don't know C++ here is the file. Just replace the ReadingXMP.cpp file in the source folder.</p> <p><a title="ReadingXMP.cpp.zip" href="http://www.bayes.co.uk/blog/file.axd?file=2010%2f01%2fReadingXMP.cpp.zip" target="_blank">ReadingXMP.cpp.zip</a></p> <p>Build the solution and you will get a ReadingXMP.exe file in the targets folder. In case you don't want to go to all that trouble here is the executable.</p> <p><a title="ReadingXMP.exe.zip" href="http://www.bayes.co.uk/blog/file.axd?file=2010%2f01%2fReadingXMP.exe.zip" target="_blank">ReadingXMP.exe.zip</a></p> <p>You can use it from the DOS command line</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:579130ea-deb2-4d90-9dfe-e337830db05d" class="wlWriterSmartContent"><div class="powershellbackground">> ReadingXMP.exe somefile.jpg</div></div> <p></p> <p>You can extract the data into a 'sidecar file' like this</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:7f599aa8-59a1-437a-82e9-2b2f1add9863" class="wlWriterSmartContent"><div class="powershellbackground">> ReadingXMP.exe somefile.jpg > somefile.jpg.xmp</div></div> <p></p> <p>You can use it in Powershell like this</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:9b5fc77d-1d57-43ad-80e5-1947493cc26e" class="wlWriterSmartContent"><div class="powershellbackground">PS> [xml]$xmp = (.\ReadingXMP.exe somefile.jpg)</div></div> <p></p> <p>Which reads the XMP RDF directly into the $xmp object.</p> <p>To keep in the theme of my previous posts a useful -CustomProps param for Get-DirAsXml can go something like this if you only want one or two properties (or just use WIC).</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:c2aff2c0-bbf2-48bd-a669-13853488e99c" class="wlWriterSmartContent"><div class='highlightbackground'> <span class='command'>get-dirasxml</span>&nbsp;<span class='commandarg'>..\test</span>&nbsp;<span class='commandparam'>-CustomProps</span>&nbsp;<span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>param</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$element</span><span class='operator'>,</span>&nbsp;<span class='variable'>$directory</span><span class='operator'>,</span>&nbsp;<span class='variable'>$file</span><span class='operator'>,</span>&nbsp;<span class='variable'>$prefix</span><span class='operator'>,</span>&nbsp;<span class='variable'>$namespace</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>try</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>[xml]</span><span class='variable'>$xmp</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='foreground'>(</span><span class='command'>.\ReadingXMP.exe</span>&nbsp;<span class='variable'>$file</span><span class='operator'>.</span><span class='foreground'>FullName</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$long</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='variable'>$xmp</span><span class='operator'>.</span><span class='foreground'>SelectSingleNode</span><span class='foreground'>(</span><span class='string'>"//*[local-name()&nbsp;=&nbsp;'GPSLongitude']/text()"</span><span class='foreground'>)</span><span class='operator'>.</span><span class='foreground'>Value</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$lati</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='variable'>$xmp</span><span class='operator'>.</span><span class='foreground'>SelectSingleNode</span><span class='foreground'>(</span><span class='string'>"//*[local-name()&nbsp;=&nbsp;'GPSLatitude']/text()"</span><span class='foreground'>)</span><span class='operator'>.</span><span class='foreground'>Value</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>[void]</span><span class='variable'>$element</span><span class='operator'>.</span><span class='foreground'>SetAttribute</span><span class='foreground'>(</span><span class='string'>"GPSLongitude"</span><span class='operator'>,</span>&nbsp;<span class='variable'>$namespace</span><span class='operator'>,</span>&nbsp;<span class='variable'>$long</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>[void]</span><span class='variable'>$element</span><span class='operator'>.</span><span class='foreground'>SetAttribute</span><span class='foreground'>(</span><span class='string'>"GPSLatitude"</span><span class='operator'>,</span>&nbsp;<span class='variable'>$namespace</span><span class='operator'>,</span>&nbsp;<span class='variable'>$lati</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><span class='keyword'>catch</span><span class='foreground'>{</span><span class='foreground'>}</span><br /> <span class='foreground'>}</span>&nbsp;<span class='operator'>|</span>&nbsp;<span class='command'>Format-Xml</span> </div> </div> <p>and might produce </p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:26116f79-ad2b-46eb-9497-385474be3281" class="wlWriterSmartContent"><div class="highlightbackground"><div class="xml">&lt;<span class="element">root</span> <span class="attribute">Name</span>="<span class="attributetext">root</span>" <span class="attribute">Root</span>="<span class="attributetext">True</span>" <span class="attribute">Date</span>="<span class="attributetext">2010/01/22 01:24:45</span>"&gt;<span class="text"><br>     </span>&lt;<span class="element">folder</span> <span class="attribute">Name</span>="<span class="attributetext">test</span>" <span class="attribute">Base</span>="<span class="attributetext">D:\powershell\blog\test</span>" <span class="attribute">Parent</span>="<span class="attributetext">D:\powershell\blog</span>"&gt;<span class="text"><br>         </span>&lt;<span class="element">folder</span> <span class="attribute">Name</span>="<span class="attributetext">test2</span>"&gt;<span class="text"><br>             </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.ps1</span>" /&gt;<span class="text"><br>             </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.txt</span>" /&gt;<span class="text"><br>             </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.zip</span>" /&gt;<span class="text"><br>             </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">tmp.xml</span>" /&gt;<span class="text"><br>         </span>&lt;/<span class="element">folder</span>&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.jpg</span>" <span class="attribute">GPSLongitude</span>="<span class="attributetext">0,0E</span>" <span class="attribute">GPSLatitude</span>="<span class="attributetext">51,28.927873651518N</span>" /&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.ps1</span>" /&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.txt</span>" /&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.zip</span>" /&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">tmp.xml</span>" /&gt;<span class="text"><br>     </span>&lt;/<span class="element">folder</span>&gt;<span class="text"><br> </span>&lt;/<span class="element">root</span>&gt;<br> </div> </div></div> <p></p> <p>If you want the whole XMP RDF packet you can do something like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:548c480b-980b-4942-b9c7-c071512ed5ed" class="wlWriterSmartContent"><div class='highlightbackground'> <span class='command'>get-dirasxml</span>&nbsp;<span class='commandarg'>..\test</span>&nbsp;<span class='commandparam'>-CustomProps</span>&nbsp;<span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>param</span>&nbsp;<span class='foreground'>(</span><span class='variable'>$element</span><span class='operator'>,</span>&nbsp;<span class='variable'>$directory</span><span class='operator'>,</span>&nbsp;<span class='variable'>$file</span><span class='operator'>,</span>&nbsp;<span class='variable'>$prefix</span><span class='operator'>,</span>&nbsp;<span class='variable'>$namespace</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='keyword'>try</span><span class='foreground'>{</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>[xml]</span><span class='variable'>$xmp</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='foreground'>(</span><span class='command'>.\ReadingXMP.exe</span>&nbsp;<span class='variable'>$file</span><span class='operator'>.</span><span class='foreground'>FullName</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$xmpr</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='variable'>$xmp</span><span class='operator'>.</span><span class='foreground'>SelectSingleNode</span><span class='foreground'>(</span><span class='string'>"/*"</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='variable'>$inode</span>&nbsp;<span class='operator'>=</span>&nbsp;<span class='variable'>$element</span><span class='operator'>.</span><span class='foreground'>OwnerDocument</span><span class='operator'>.</span><span class='foreground'>ImportNode</span><span class='foreground'>(</span><span class='variable'>$xmpr</span><span class='operator'>,</span>&nbsp;<span class='variable'>$true</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='type'>[void]</span><span class='variable'>$element</span><span class='operator'>.</span><span class='foreground'>AppendChild</span><span class='foreground'>(</span><span class='variable'>$inode</span><span class='foreground'>)</span><br /> &nbsp;&nbsp;&nbsp;&nbsp;<span class='foreground'>}</span><span class='keyword'>catch</span><span class='foreground'>{</span><span class='foreground'>}</span><br /> <span class='foreground'>}</span>&nbsp;<span class='operator'>|</span>&nbsp;<span class='command'>Format-Xml</span> </div></div> <p>Which might produce something like this</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:0e7e754e-dc35-42f2-b43f-84a7ec207041" class="wlWriterSmartContent"><div class="highlightbackground"><div class="xml">&lt;<span class="element">root</span> <span class="attribute">Name</span>="<span class="attributetext">root</span>" <span class="attribute">Root</span>="<span class="attributetext">True</span>" <span class="attribute">Date</span>="<span class="attributetext">2010/01/22 02:00:07</span>"&gt;<span class="text"><br>     </span>&lt;<span class="element">folder</span> <span class="attribute">Name</span>="<span class="attributetext">test</span>" <span class="attribute">Base</span>="<span class="attributetext">D:\powershell\blog\test</span>" <span class="attribute">Parent</span>="<span class="attributetext">D:\powershell\blog</span>"&gt;<span class="text"><br>         </span>&lt;<span class="element">folder</span> <span class="attribute">Name</span>="<span class="attributetext">test2</span>"&gt;<span class="text"><br>             </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.ps1</span>" /&gt;<span class="text"><br>             </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.txt</span>" /&gt;<span class="text"><br>             </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.zip</span>" /&gt;<span class="text"><br>             </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">tmp.xml</span>" /&gt;<span class="text"><br>         </span>&lt;/<span class="element">folder</span>&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.jpg</span>"&gt;<span class="text"><br>             </span>&lt;<span class="nsprefix">x</span>:<span class="element">xmpmeta</span><span class="attribute"> xmlns:x</span>="<span class="attributetext">adobe:ns:meta/</span>"&gt;<span class="text"><br>                 </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">RDF</span><span class="attribute"> xmlns:rdf</span>="<span class="attributetext">http://www.w3.org/1999/02/22-rdf-syntax-ns#</span>"&gt;<span class="text"><br>                     </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Description</span><span class="attribute"> xmlns:dc</span>="<span class="attributetext">http://purl.org/dc/elements/1.1/</span>" <span class="attribute">rdf:about</span>="<span class="attributetext">uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b</span>"&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">dc</span>:<span class="element">subject</span>&gt;<span class="text"><br>                             </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Bag</span>&gt;<span class="text"><br>                                 </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">li</span>&gt;<span class="text">Chris</span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">li</span>&gt;<span class="text"><br>                             </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Bag</span>&gt;<span class="text"><br>                         </span>&lt;/<span class="nsprefix">dc</span>:<span class="element">subject</span>&gt;<span class="text"><br>                     </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                     </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Description</span><span class="attribute"> xmlns:MicrosoftPhoto</span>="<span class="attributetext">http://ns.microsoft.com/photo/1.0</span>" <span class="attribute">rdf:about</span>="<span class="attributetext">uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b</span>"&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">MicrosoftPhoto</span>:<span class="element">LastKeywordXMP</span>&gt;<span class="text"><br>                             </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Bag</span>&gt;<span class="text"><br>                                 </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">li</span>&gt;<span class="text">Chris</span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">li</span>&gt;<span class="text"><br>                             </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Bag</span>&gt;<span class="text"><br>                         </span>&lt;/<span class="nsprefix">MicrosoftPhoto</span>:<span class="element">LastKeywordXMP</span>&gt;<span class="text"><br>                     </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                     </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Description</span><span class="attribute"> xmlns:MP</span>="<span class="attributetext">http://ns.microsoft.com/photo/1.2/</span>"&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">MP</span>:<span class="element">RegionInfo</span>&gt;<span class="text"><br>                             </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                                 </span>&lt;<span class="nsprefix">MPRI</span>:<span class="element">Regions</span><span class="attribute"> xmlns:MPRI</span>="<span class="attributetext">http://ns.microsoft.com/photo/1.2/t/RegionInfo#</span>"&gt;<span class="text"><br>                                     </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Bag</span>&gt;<span class="text"><br>                                         </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">li</span>&gt;<span class="text"><br>                                             </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                                                 </span>&lt;<span class="nsprefix">MPReg</span>:<span class="element">Rectangle</span><span class="attribute"> xmlns:MPReg</span>="<span class="attributetext">http://ns.microsoft.com/photo/1.2/t/Region#</span>"&gt;<span class="text"><br>                                                     0.200521, 0.257813, 0.072917, 0.054688<br>                                                 </span>&lt;/<span class="nsprefix">MPReg</span>:<span class="element">Rectangle</span>&gt;<span class="text"><br>                                                 </span>&lt;<span class="nsprefix">MPReg</span>:<span class="element">PersonDisplayName</span><span class="attribute"> xmlns:MPReg</span>="<span class="attributetext">http://ns.microsoft.com/photo/1.2/t/Region#</span>"&gt;<span class="text"><br>                                                     Chris Bayes</span>&lt;/<span class="nsprefix">MPReg</span>:<span class="element">PersonDisplayName</span>&gt;<span class="text"><br>                                                     </span>&lt;<span class="nsprefix">MPReg</span>:<span class="element">PersonEmailDigest</span><span class="attribute"> xmlns:MPReg</span>="<span class="attributetext">http://ns.microsoft.com/photo/1.2/t/Region#</span>"&gt;<span class="text"><br>                                                         267675C2A3CDXXXXXXXXXX799647B6CA144<br>                                                     </span>&lt;/<span class="nsprefix">MPReg</span>:<span class="element">PersonEmailDigest</span>&gt;<span class="text"><br>                                                     </span>&lt;<span class="nsprefix">MPReg</span>:<span class="element">PersonLiveIdCID</span><span class="attribute"> xmlns:MPReg</span>="<span class="attributetext">http://ns.microsoft.com/photo/1.2/t/Region#</span>"&gt;<span class="text"><br>                                                         -46641XXXXXXX70720<br>                                                     </span>&lt;/<span class="nsprefix">MPReg</span>:<span class="element">PersonLiveIdCID</span>&gt;<span class="text"><br>                                                 </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                                         </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">li</span>&gt;<span class="text"><br>                                     </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Bag</span>&gt;<span class="text"><br>                                 </span>&lt;/<span class="nsprefix">MPRI</span>:<span class="element">Regions</span>&gt;<span class="text"><br>                             </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                         </span>&lt;/<span class="nsprefix">MP</span>:<span class="element">RegionInfo</span>&gt;<span class="text"><br>                     </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                     </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Description</span><span class="attribute"> xmlns:xmp</span>="<span class="attributetext">http://ns.adobe.com/xap/1.0/</span>"&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">xmp</span>:<span class="element">CreatorTool</span>&gt;<span class="text">Microsoft Windows Live Photo Gallery14.0.8081.709</span>&lt;/<span class="nsprefix">xmp</span>:<span class="element">CreatorTool</span>&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">xmp</span>:<span class="element">creatortool</span>&gt;<span class="text">Microsoft Pro Photo Tools</span>&lt;/<span class="nsprefix">xmp</span>:<span class="element">creatortool</span>&gt;<span class="text"><br>                     </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                     </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Description</span><span class="attribute"> xmlns:tiff</span>="<span class="attributetext">http://ns.adobe.com/tiff/1.0/</span>"&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">tiff</span>:<span class="element">Software</span>&gt;<span class="text">Microsoft Windows Live Photo Gallery14.0.8081.709</span>&lt;/<span class="nsprefix">tiff</span>:<span class="element">Software</span>&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">tiff</span>:<span class="element">software</span>&gt;<span class="text">Microsoft Pro Photo Tools</span>&lt;/<span class="nsprefix">tiff</span>:<span class="element">software</span>&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">tiff</span>:<span class="element">Orientation</span>&gt;<span class="text">1</span>&lt;/<span class="nsprefix">tiff</span>:<span class="element">Orientation</span>&gt;<span class="text"><br>                     </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                     </span>&lt;<span class="nsprefix">rdf</span>:<span class="element">Description</span><span class="attribute"> xmlns:exif</span>="<span class="attributetext">http://ns.adobe.com/exif/1.0/</span>"&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">exif</span>:<span class="element">GPSLatitude</span>&gt;<span class="text">51,28.927873651518N</span>&lt;/<span class="nsprefix">exif</span>:<span class="element">GPSLatitude</span>&gt;<span class="text"><br>                         </span>&lt;<span class="nsprefix">exif</span>:<span class="element">GPSLongitude</span>&gt;<span class="text">0,0E</span>&lt;/<span class="nsprefix">exif</span>:<span class="element">GPSLongitude</span>&gt;<span class="text"><br>                     </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">Description</span>&gt;<span class="text"><br>                 </span>&lt;/<span class="nsprefix">rdf</span>:<span class="element">RDF</span>&gt;<span class="text"><br>             </span>&lt;/<span class="nsprefix">x</span>:<span class="element">xmpmeta</span>&gt;<span class="text"><br>         </span>&lt;/<span class="element">file</span>&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.ps1</span>" /&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.txt</span>" /&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">test.zip</span>" /&gt;<span class="text"><br>         </span>&lt;<span class="element">file</span> <span class="attribute">Name</span>="<span class="attributetext">tmp.xml</span>" /&gt;<span class="text"><br>     </span>&lt;/<span class="element">folder</span>&gt;<span class="text"><br> </span>&lt;/<span class="element">root</span>&gt;<br> </div> </div></div> <p></p> <p>and is quite large. Whether to leave the XMP RDF in the file, in sidecar files, or in DAXml, depends on your&nbsp; 'application/ps1 easy script', and how many files you have in your own folders. </p> <p>I guess the point is that you have easy access to your own data.</p> <p>P.S. I should have looked harder. <a title="ExifTool by Phil Harvey" href="http://www.sno.phy.queensu.ca/~phil/exiftool/" target="_blank">ExifTool by Phil Harvey</a> does all of this and more. I assumed from the name that it works on EXIF metadata but it can output all metadata as XMP i.e.</p> <p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:67c4061b-dcd5-4217-bbf3-e1f1b5c771e6" class="wlWriterSmartContent"><div class="powershellbackground">PS> .\exiftool test.jpg -s -o .\%d%f.xmp</div></div></p> <p>will create sidecar files and doing something like this (less than obvious)</p> <p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:bb646d62-45bb-4029-8643-b904bbdeaeab" class="wlWriterSmartContent"><div class='highlightbackground'> <span class='type'>[xml]</span><span class='variable'>$xmp</span><span class='operator'>=</span><span class='foreground'>(</span><span class='command'>.\exiftool</span>&nbsp;<span class='commandparam'>-xmp -b -m</span>&nbsp;<span class='variable'>$file</span><span class='operator'>.</span><span class='foreground'>FullName</span><span class='foreground'>)</span> </div> </div></p> <p>will produce the equivalent to the xml in the sidecar file. -X though will produce "RDF/Xml" which is less useful.</p>
http://www.bayes.co.uk/blog/post/XMP-Getting-Raw-XMP-RDF-Using-Adobe-XMP-Toolkit.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=0a32a5cf-4a8c-487f-9157-7feabd606477 Fri, 22 Jan 2010 14:44:25 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=0a32a5cf-4a8c-487f-9157-7feabd606477 39 http://www.bayes.co.uk/blog/trackback.axd?id=0a32a5cf-4a8c-487f-9157-7feabd606477 http://www.bayes.co.uk/blog/post/XMP-Getting-Raw-XMP-RDF-Using-Adobe-XMP-Toolkit.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=0a32a5cf-4a8c-487f-9157-7feabd606477

Powershell Xml Folder Tree Xaml Explorer

<p>A different way to display the output from Get-DirAsXml is with Xaml. I will probably occasionally refer back to the previous posts on how to do it using Windows.Forms. So here is step one, displaying the output as a simple TreeView</p> <div class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">Xaml-DisplayDir</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span><span class="foreground">(</span><span class="type">[xml]</span><span class="variable">$xml</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$xaml</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@"</span><br> <div class="xml"><span class="element">&lt;<span class="element">Window</span><span class="attribute"> <br>&nbsp;&nbsp;&nbsp; xmlns</span>="<span class="attributetext">http://schemas.microsoft.com/winfx/2006/xaml/presentation</span>"<span class="attribute"> <br>&nbsp;&nbsp;&nbsp; xmlns:x</span>="<span class="attributetext">http://schemas.microsoft.com/winfx/2006/xaml</span>" <br>&nbsp;&nbsp;&nbsp; <span class="attribute">Title</span>="<span class="attributetext">Xaml-DisplayDir</span>" <br>&nbsp;&nbsp;&nbsp; <span class="attribute">Height</span>="<span class="attributetext">300</span>" <span class="attribute">Width</span>="<span class="attributetext">600</span>" <br>&nbsp;&nbsp;&nbsp; <span class="attribute">ResizeMode</span>="<span class="attributetext">CanResizeWithGrip</span>" <br>&nbsp;&nbsp;&nbsp; <span class="attribute">WindowStyle</span>="<span class="attributetext">SingleBorderWindow</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Window.Resources</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">XmlDataProvider</span> <span class="attribute">x:Key</span>="<span class="attributetext">DirectoryData</span>" <span class="attribute">XPath</span>="<span class="attributetext">/DAXContainer/*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">x</span>:<span class="element">XData</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">DAXContainer</span><span class="nsprefix"> xmlns</span>=""&gt;<span style="background-color: yellow" class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $($xml.SelectSingleNode("/*").OuterXml)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/<span class="element">DAXContainer</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">x</span>:<span class="element">XData</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">XmlDataProvider</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">HierarchicalDataTemplate</span> <span class="attribute">x:Key</span>="<span class="attributetext">FolderTemplate</span>" <span class="attribute">ItemsSource</span>="<span class="attributetext">{Binding XPath=folder}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">StackPanel</span> <span class="attribute">Orientation</span>="<span class="attributetext">Horizontal</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">TextBlock</span> <span class="attribute">Text</span>="<span class="attributetext">{Binding XPath=@Name}</span>" <span class="attribute">Margin</span>="<span class="attributetext">2,0,0,0</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">StackPanel</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">HierarchicalDataTemplate</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">DataTemplate</span> <span class="attribute">x:Key</span>="<span class="attributetext">FileTemplate</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">StackPanel</span> <span class="attribute">Orientation</span>="<span class="attributetext">Horizontal</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">TextBlock</span> <span class="attribute">Text</span>="<span class="attributetext">{Binding XPath=@Name}</span>" <span class="attribute">Margin</span>="<span class="attributetext">0,0,0,0</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">StackPanel</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">DataTemplate</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Window.Resources</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Grid</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">TreeView</span> <span class="attribute">Margin</span>="<span class="attributetext">0, 0, 0, 0</span>" <span class="attribute">Name</span>="<span class="attributetext">TREEVIEW</span>" <span class="attribute">HorizontalAlignment</span>="<span class="attributetext">Stretch</span>" <span class="attribute">DataContext</span>="<span class="attributetext">{Binding Source={StaticResource DirectoryData}, XPath=/DAXContainer/*}</span>" <span class="attribute">ItemTemplate</span>="<span class="attributetext">{StaticResource FolderTemplate}</span>" <span class="attribute">ItemsSource</span>="<span class="attributetext">{Binding}</span>" /&gt;<span class="text"><br></span><span class="text">&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Grid</span>&gt;<span class="text"><br></span>&lt;/<span class="element">Window</span>&gt;</span><br></div><span class="string">"@</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$RESULT</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">""</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$WINDOW</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[Windows.Markup.XamlReader]</span><span class="operator">::</span><span class="foreground">Load</span><span class="foreground">(</span><span class="foreground">(</span><span class="command">New-Object</span>&nbsp;<span class="commandarg">System.Xml.XmlNodeReader</span><span class="foreground">(</span><span class="type">[xml]</span><span class="variable">$xaml</span><span class="foreground">)</span><span class="foreground">)</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$TREEVIEW</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$WINDOW</span><span class="operator">.</span><span class="foreground">FindName</span><span class="foreground">(</span><span class="string">"TREEVIEW"</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$TREEVIEW</span><span class="operator">.</span><span class="foreground">add_SelectedItemChanged</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$RESULT</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$this</span><span class="operator">.</span><span class="foreground">Selecteditem</span><span class="operator">.</span><span class="foreground">Name</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">write-host</span>&nbsp;<span class="string">"SelectedItemChanged"</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="type">[void]</span><span class="variable">$WINDOW</span><span class="operator">.</span><span class="foreground">ShowDialog</span><span class="foreground">(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$WINDOW</span><span class="operator">.</span><span class="foreground">Close</span><span class="foreground">(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$WINDOW</span><span class="operator">.</span><span class="foreground">Dispose</span><span class="foreground">(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$RESULT</span><br><span class="foreground">}</span></div> <p>There are a few things going on here.</p> <ol> <li>The whole thing is a Powershell Mashup script. <li>It declares a here-string that contains the Xaml markup. <li>It inserts the Xml into the middle of the Xaml markup. (highlighted) <li>It creates a Window object from the resulting markup. <li>It adds a simple event handler to the TREEVIEW object. <li>Displays the result. </li></ol> <p>I like to think of it like this. Get-DirAsXml is used to get some Xml, the Xml is docorated or transformed (step 3 above. The Xml is wrapped in Xaml), the resulting Xml is displayed in a window.</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=transformdiagram1_2.jpg"><img alt="transformdiagram1" src="http://www.bayes.co.uk/blog/image.axd?picture=transformdiagram1_thumb_2.jpg" width="440" height="121"></a></p> <p>It can be used like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:b86341af-dc69-4cf8-9dd6-b0f839e7bc12" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\Xaml-DisplayDir.ps1 # dot source the script<br>PS&gt; Xaml-DisplayDir (Get-DirAsXml test)<br></div></div> <p>It might be displayed like this</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDir.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDir" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDir_thumb.jpg" width="244" height="193"></a></p> <p>Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fXaml-DisplayDir.zip">Xaml-DisplayDir.zip (1.09 kb)</a></p> <p>So onto the next step. Add a ListView to display the files. This code will do it</p> <div class="highlightbackground"> <div class="xml">&lt;<span class="element">ListView</span> <span class="attribute">Name</span>="<span class="attributetext">LISTVIEW</span>" <span class="attribute">Grid.Column</span>="<span class="attributetext">2</span>" <span class="attribute">HorizontalAlignment</span>="<span class="attributetext">Stretch</span>" <span class="attribute">ItemsSource</span>="<span class="attributetext">{Binding Path=SelectedItem, ElementName=TREEVIEW, Mode=OneWay}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">ListView.View</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">GridView</span> <span class="attribute">AllowsColumnReorder</span>="<span class="attributetext">true</span>" <span class="attribute">ColumnHeaderContainerStyle</span>="<span class="attributetext">{DynamicResource CustomHeaderStyle}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">GridViewColumn</span> <span class="attribute">Header</span>="<span class="attributetext">Name</span>" <span class="attribute">CellTemplate</span>="<span class="attributetext">{StaticResource ItemTemplate}</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">GridViewColumn</span> <span class="attribute">DisplayMemberBinding</span>="<span class="attributetext">{Binding XPath=@Length}</span>" <span class="attribute">Header</span>="<span class="attributetext">Length</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">GridViewColumn</span> <span class="attribute">DisplayMemberBinding</span>="<span class="attributetext">{Binding XPath=@LastWriteTime}</span>" <span class="attribute">Header</span>="<span class="attributetext">Date</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">GridView</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">ListView.View</span>&gt;<span class="text"><br></span>&lt;/<span class="element">ListView</span>&gt;<br></div></div> <p>This adds a ListView with 3 columns Name, Length and Date. The columns will display the data specified in the XPath binding i.e. @Name, @Length, @LastWriteTime. We don't need to do anything like add an event handler to populate and display the items in the list because the ListView.ItemSource attribute is 'bound' to the TREEVIEW.SelectedItem.</p> <p>We also want to add icons for the folders and files. Rather than using an ImageList and indexing into it like Forms, Xaml is a bit more like html and uses markup to display an image and the text. Like this StackPanel</p> <div class="highlightbackground"> <div class="xml">&lt;<span class="element">DataTemplate</span><span class="attribute"> xmlns:x</span>="<span class="attributetext">http://schemas.microsoft.com/winfx/2006/xaml</span>" <span class="attribute">x:Key</span>="<span class="attributetext">ItemTemplate</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">StackPanel</span> <span class="attribute">Orientation</span>="<span class="attributetext">Horizontal</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Image</span> <span class="attribute">Width</span>="<span class="attributetext">16</span>" <span class="attribute">Height</span>="<span class="attributetext">16</span>" <span class="attribute">Stretch</span>="<span class="attributetext">Fill</span>" <span class="attribute">Source</span>="<span class="attributetext">ico2.png</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">TextBlock</span> <span class="attribute">Text</span>="<span class="attributetext">{Binding XPath=@Name}</span>" <span class="attribute">Margin</span>="<span class="attributetext">0,0,0,0</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">StackPanel</span>&gt;<span class="text"><br></span>&lt;/<span class="element">DataTemplate</span>&gt;<br></div></div> <p>It might be displayed like this</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExp.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExp" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExp_thumb.jpg" width="244" height="119"></a></p> <p>You will notice that the folder test2 in the listview has the wrong icon. This can be fixed with a Trigger.</p> <div class="highlightbackground"> <div class="xml">&lt;<span class="element">Style</span> <span class="attribute">TargetType</span>="<span class="attributetext">Image</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Style.Triggers</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">DataTrigger</span> <span class="attribute">Binding</span>="<span class="attributetext">{Binding Path=Name}</span>" <span class="attribute">Value</span>="<span class="attributetext">folder</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Setter</span> <span class="attribute">Property</span>="<span class="attributetext">Source</span>" <span class="attribute">Value</span>="<span class="attributetext">{StaticResource FolderImage}</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">DataTrigger</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">DataTrigger</span> <span class="attribute">Binding</span>="<span class="attributetext">{Binding Path=Name}</span>" <span class="attribute">Value</span>="<span class="attributetext">file</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Setter</span> <span class="attribute">Property</span>="<span class="attributetext">Source</span>" <span class="attribute">Value</span>="<span class="attributetext">{StaticResource FileImage}</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">DataTrigger</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Style.Triggers</span>&gt;<span class="text"><br></span>&lt;/<span class="element">Style</span>&gt;<br></div></div> <p>I would like to bind the DataTrigger to XPath=local-name() but XPath functions are not supported DOH!</p> <p>To keep things self contained I have set the Image.Source property to rather badly drawn Xaml icons.</p> <p>It can be used like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:d17c83f6-21be-4f27-8582-fd9b62d5392c" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\Xaml-DisplayDirExp.ps1 # dot source the script<br>PS&gt; Xaml-DisplayDirExp (Get-DirAsXml test -props @{Length="";LastWriteTime=""} )<br></div></div> <p>Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fXaml-DisplayDirExp.zip">Xaml-DisplayDirExp.zip (2.22 kb)</a></p> <p>Because Xaml is Xml we can process it with Xslt. We can add a little identity transform to our script that has an aditional template to hande the DAXContainer</p> <div class="highlightbackground"><span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"> xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>" <span class="attribute">version</span>="<span class="attributetext">1.0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">param</span> <span class="attribute">name</span>="<span class="attributetext">DAX</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">node()|@*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">DAXContainer</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">DAXContainer</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy-of</span> <span class="attribute">select</span>="<span class="attributetext">$DAX</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">DAXContainer</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div><span class="string">'@</span><br><span class="type">[xml]</span><span class="variable">$resultxaml</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">(</span><span class="command">Invoke-Transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$xaml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-arguments</span>&nbsp;<span class="foreground">@{</span><span class="string">'DAX'</span><span class="operator">=</span><span class="variable">$xml</span><span class="foreground">}</span><span class="foreground">)</span><br></div> <p><span><font size="1">This is a simple T-DaxDecorate Translet. (Notice that the single quote Here-String from Powershell is used for $xslt. This is to avoid Powershell's symbol substitution that would have translated&nbsp; <span class="kwrd">&lt;</span><span class="html">xsl:copy-of</span> <span class="attr">select</span><span class="kwrd">="$DAX"</span> <span class="kwrd">/&gt;</span> into invalid Xslt.)</font></span></p> <p>The Invoke-Transform is taking the Xaml as the input Xml and the motherload xml is passed as a parameter and copied directly to the output. Something like this</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=transformdiagram2_1.jpg"><img alt="transformdiagram2" src="http://www.bayes.co.uk/blog/image.axd?picture=transformdiagram2_thumb_1.jpg" width="440" height="186"></a></p> <p>It can be used like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:caa0f98a-f2a4-4118-9c89-88037d43cd3b" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\Xaml-DisplayDirExpXslt.ps1 # dot source the script<br>PS&gt; Xaml-DisplayDirExp (Get-DirAsXml test -props @{Length="";LastWriteTime=""} )<br></div></div> <p>Here is the code</p> <p>&nbsp;<a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fXaml-DisplayDirExpXslt.zip">Xaml-DisplayDirExpXslt.zip (1.99 kb)</a></p> <p>As in the Forms version we will want to specify the columns that are displayed. So far the Name, Length and LastWriteTime are hard coded in the Xaml Form but we can pass another Xml into the mix that specifies the columns we want. Something like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:9ab839ee-90cf-4dbe-b462-dbe3c4b00171" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; Xaml-DisplayDirExp (Get-DirAsXml test -props @{Length=""; LastWriteTime=""} -ExtendedProps @{Title=""; Subject=""; Author=""; Category=""; Keywords=""; Comments=""}) <u>-columns ([xml]"&lt;columns&gt;&lt;c n='Length' b='@Length' /&gt;&lt;c n='Date' b='@LastWriteTime' /&gt;&lt;/columns&gt;"</u>)<br></div></div> <p>The nice thing about this is that the column name and the columns binding path can be specified.</p> <div class="highlightbackground"><span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"> xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>"<span class="attribute"> xmlns:xaml</span>="<span class="attributetext">http://schemas.microsoft.com/winfx/2006/xaml/presentation</span>" <span class="attribute">version</span>="<span class="attributetext">1.0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">param</span> <span class="attribute">name</span>="<span class="attributetext">COLUMNS</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">node()|@*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">xaml:ListView[@Name='LISTVIEW']/xaml:ListView.View/xaml:GridView</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">$COLUMNS/columns/c</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">columns/c</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xaml</span>:<span class="element">GridViewColumn</span> <span class="attribute">DisplayMemberBinding</span>="<span class="attributetext">{{Binding XPath={@b}}}</span>" <span class="attribute">Header</span>="<span class="attributetext">{@n}</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div><span class="string">'@</span><br><span class="type">[xml]</span><span class="variable">$resultxaml</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">(</span><span class="command">Invoke-Transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$xaml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-arguments</span>&nbsp;<span class="foreground">@{</span><span class="foreground">COLUMNS</span><span class="operator">=</span><span class="variable">$columns</span><span class="foreground">}</span><span class="foreground">)</span><br><br></div> <p><span><font size="1">This is a simple T-DaxExplorerColumn Translet (Notice that the curly braces in the DisplayMemberBinding are escaped to avoid Xslt AVT substitution.)</font></span></p> <p>We can expand it to specify that we want column justification</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:9afab581-6e82-4e33-a438-b6d9187bdb8c" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; Xaml-DisplayDirExp (Get-DirAsXml test -props @{Length=""; LastWriteTime=""} -ExtendedProps @{Title=""; Subject=""; Author=""; Category=""; Keywords=""; Comments=""}) <u>-columns ([xml]"&lt;columns&gt;&lt;c n='Length' b='@Length' j='Right' /&gt;&lt;c n='Date' b='@LastWriteTime' j='Right' /&gt;&lt;/columns&gt;"</u>)<br></div></div> <p></p> <div class="highlightbackground"><span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"> xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>"<span class="attribute"> xmlns:xaml</span>="<span class="attributetext">http://schemas.microsoft.com/winfx/2006/xaml/presentation</span>" <span class="attribute">version</span>="<span class="attributetext">1.0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">param</span> <span class="attribute">name</span>="<span class="attributetext">COLUMNS</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">node()|@*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">xaml:ListView[@Name='LISTVIEW']/xaml:ListView.View/xaml:GridView</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">$COLUMNS/columns/c</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">columns/c</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xaml</span>:<span class="element">GridViewColumn</span> <span class="attribute">Header</span>="<span class="attributetext">{@n}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xaml</span>:<span class="element">GridViewColumn.CellTemplate</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xaml</span>:<span class="element">DataTemplate</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xaml</span>:<span class="element">TextBlock</span> <span class="attribute">Text</span>="<span class="attributetext">{{Binding XPath={@b}}}</span>" <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="attribute">TextAlignment</span>="<span class="attributetext"><a href="mailto:{@j">{@j</a>}</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xaml</span>:<span class="element">DataTemplate</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xaml</span>:<span class="element">GridViewColumn.CellTemplate</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xaml</span>:<span class="element">GridViewColumn</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div><span class="string">'@</span><br><span class="type">[xml]</span><span class="variable">$resultxaml</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">(</span><span class="command">Invoke-Transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$xaml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-arguments</span>&nbsp;<span class="foreground">@{</span><span class="foreground">COLUMNS</span><span class="operator">=</span><span class="variable">$columns</span><span class="foreground">}</span><span class="foreground">)</span><br><br></div> <p><span><font size="1">This is a simple T-DaxExplorerColumnWithJustify Translet</font></span></p> <p>For this to work properly we need to add a Style to the ListViewItem that will contain the TextBlock. It needs to stretch to fill the grid cell. This style can go into a Resources section that is in scope. I put it into the Window.Resources section.</p> <div class="highlightbackground"> <div class="xml">&lt;<span class="element">Style</span> <span class="attribute">TargetType</span>="<span class="attributetext">{x:Type ListViewItem}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Setter</span> <span class="attribute">Property</span>="<span class="attributetext">HorizontalContentAlignment</span>" <span class="attribute">Value</span>="<span class="attributetext">Stretch</span>" /&gt;<span class="text"><br></span>&lt;/<span class="element">Style</span>&gt;</div></div> <p>It might be displayed like this.</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpXsltColumns.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExpXsltColumns" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpXsltColumns_thumb.jpg" width="244" height="128"></a></p> <p>Here is the code</p> <p>&nbsp;<a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fXaml-DisplayDirExpXsltColumns.zip">Xaml-DisplayDirExpXsltColumns.zip (2.21 kb)</a></p> <p>Adding a ToolTip to items in the ListView is easy. We just have to add a ToolTip property to the ItemTemplate StackPanel and bind it to the InfoTip attribute.</p> <div class="highlightbackground"> <div class="xml">&lt;<span class="element">StackPanel.ToolTip</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">TextBlock</span> <span class="attribute">Text</span>="<span class="attributetext">{Binding XPath=@InfoTip}</span>" /&gt;<span class="text"><br></span>&lt;/<span class="element">StackPanel.ToolTip</span>&gt;<br></div></div> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpToolTip.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExpToolTip" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpToolTip_thumb.jpg" width="244" height="135"></a></p> <p>Adding XPath searching seems simple at first. Add a Button and a TextBox to the last Row of the Grid</p> <div class="highlightbackground"> <div class="xml">&lt;<span class="element">Grid</span> <span class="attribute">Grid.Row</span>="<span class="attributetext">2</span>" <span class="attribute">Grid.ColumnSpan</span>="<span class="attributetext">3</span>" <span class="attribute">Background</span>="<span class="attributetext">Aquamarine</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Grid.ColumnDefinitions</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">ColumnDefinition</span> <span class="attribute">Width</span>="<span class="attributetext">100</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">ColumnDefinition</span> <span class="attribute">Width</span>="<span class="attributetext">*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Grid.ColumnDefinitions</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Button</span> <span class="attribute">Name</span>="<span class="attributetext">SEARCHBUTTON</span>" <span class="attribute">Content</span>="<span class="attributetext">Search</span>" <span class="attribute">Width</span>="<span class="attributetext">100</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">TextBox</span> <span class="attribute">Name</span>="<span class="attributetext">SEARCHTEXT</span>" <span class="attribute">Grid.Column</span>="<span class="attributetext">2</span>" <span class="attribute">HorizontalAlignment</span>="<span class="attributetext">Stretch</span>" <span class="attribute">Width</span>="<span class="attributetext">Auto</span>" /&gt;<span class="text"><br></span>&lt;/<span class="element">Grid</span>&gt;<br></div></div> <p>Then add a Click event to the Button and set the result of the XPath expression to the ItemsSource propert of the ListView. This works but it wrecks the binding of the ListView and further clicking on the TreeView doesn't do anything obviously. I tried a few things but in the end I decided on a 2 ListView approach. One is visible when the search button is clicked and the other when the treeview is clicked. It isn't perfect but it works until I can find a way of recreating the binding.</p> <p>It might display like this</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpSearch.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExpSearch" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpSearch_thumb.jpg" width="244" height="140"></a></p> <p>Here is the code</p> <p>&nbsp;<a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fXaml-DisplayDirExpXsltSearch.zip">Xaml-DisplayDirExpXsltSearch.zip (2.75 kb)</a></p> <p>Now that we have another control on the form it is worth applying some styling. We can add say a gradient to the button.</p> <div class="highlightbackground"> <div class="xml">&lt;<span class="element">Style</span> <span class="attribute">TargetType</span>="<span class="attributetext">{x:Type Button}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Setter</span> <span class="attribute">Property</span>="<span class="attributetext">Background</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Setter.Value</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">LinearGradientBrush</span> <span class="attribute">EndPoint</span>="<span class="attributetext">0,1</span>" <span class="attribute">StartPoint</span>="<span class="attributetext">0,0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">GradientStop</span> <span class="attribute">Color</span>="<span class="attributetext">#FF0000FF</span>" <span class="attribute">Offset</span>="<span class="attributetext">0</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">GradientStop</span> <span class="attribute">Color</span>="<span class="attributetext">#FFFFFFFF</span>" <span class="attribute">Offset</span>="<span class="attributetext">0.338</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">GradientStop</span> <span class="attribute">Color</span>="<span class="attributetext">#FFFFFFFF</span>" <span class="attribute">Offset</span>="<span class="attributetext">0.716</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">GradientStop</span> <span class="attribute">Color</span>="<span class="attributetext">#FF0000FF</span>" <span class="attribute">Offset</span>="<span class="attributetext">1</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">LinearGradientBrush</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Setter.Value</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Setter</span>&gt;<span class="text"><br></span>&lt;/<span class="element">Style</span>&gt;</div></div> <p>Styles can get very big very quickly and a way of keeping them seperate is to include them like the columns and DAXml by doing a merge in Xslt</p> <p>&nbsp;</p> <div class="highlightbackground"><span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"> xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>"<span class="attribute"> xmlns:xaml</span>="<span class="attributetext">http://schemas.microsoft.com/winfx/2006/xaml/presentation</span>" <span class="attribute">version</span>="<span class="attributetext">1.0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">param</span> <span class="attribute">name</span>="<span class="attributetext">STYLE</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">node()|@*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">xaml:Window.Resources</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">$STYLE/*/*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div><span class="string">'@</span><br><span class="type">[xml]</span><span class="variable">$resultxaml</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">(</span><span class="command">Invoke-Transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$xaml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-arguments</span>&nbsp;<span class="foreground">@{</span><span class="foreground">STYLE</span><span class="operator">=</span><span class="variable">$style</span><span class="foreground">}</span><span class="foreground">)<br></span></div> <p><font size="1">This is a simple T-DaxExplorerStyler Translet</font></p> <p>It might be displayed like this</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpSearchStyle_2.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExpSearchStyle" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpSearchStyle_thumb_2.jpg" width="244" height="124"></a></p> <p align="left">or</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpSearchStyle3.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExpSearchStyle3" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpSearchStyle3_thumb.jpg" width="244" height="119"></a>&nbsp;&nbsp; </p> <p>Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f12%2fXaml-DisplayDirExpXsltStyle.zip">Xaml-DisplayDirExpXsltStyle.zip (2.81 kb)</a>&nbsp;</p> <p>Adding Drag'n'Drop is very similar to the Forms version except there is no DragStart event and the object model is slightly different but the code is very similar. I added a third pane like before that contains a TreeView. The drag rule is simple, items can be dragged from the ListView to the right-hand TreeView. The Template for the TreeView is modified to display folders and files. The resulting Xml is put into the pipeline when the form closes.</p> <p>It might be displayed like this (without cursor)</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpDragDrop_2.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Xaml-DisplayDirExpDragDrop" src="http://www.bayes.co.uk/blog/image.axd?picture=Xaml-DisplayDirExpDragDrop_thumb_2.jpg" width="444" height="159"></a></p> <p>Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fXaml-DisplayDirExpDragDrop.zip">Xaml-DisplayDirExpDragDrop.zip (3.44 kb)</a></p>
http://www.bayes.co.uk/blog/post/Powershell-Xml-Folder-Tree-Xaml-Explorer.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=6077b6e1-f1f8-4b91-9a5d-929cd0b92115 Thu, 12 Nov 2009 15:14:00 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=6077b6e1-f1f8-4b91-9a5d-929cd0b92115 38 http://www.bayes.co.uk/blog/trackback.axd?id=6077b6e1-f1f8-4b91-9a5d-929cd0b92115 http://www.bayes.co.uk/blog/post/Powershell-Xml-Folder-Tree-Xaml-Explorer.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=6077b6e1-f1f8-4b91-9a5d-929cd0b92115

Powershell Adding an icon to a form

<p>If you are using a GUI it is nice to have a form icon. I didn't want to have an ico or bmp file in the same folder as the ps1 file because it might get lost. So this bit of code can be put into your ps1 source file to give you a form icon</p> <p><font color="#ff4500" size="2">$iconstring</font><font size="2"> </font><font color="#a9a9a9" size="2">=</font><font size="2"> (</font><font color="#8b0000" size="2">@"</font><br><font size="2">iVBORw0KGgoAAAANSUhEUgAAACAAAAAgBAMAAACB <br>VGfHAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 <br>YQUAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUw <br>AADqYAAAOpgAABdwnLpRPAAAADBQTFRFAAAAgAAA <br>AIAAgIAAAACAgACAAICAwMDAgICA/wAAAP8A//8A <br>AAD//wD/AP//////TxMmSQAAACxJREFUKM9jcEED <br>DLQSYGBgQBFw4N69gQECIALcu+GAZQQKODDAAS2j <br>gUQBAF/KwfacIWwzAAAAAElFTkSuQmCC <br>"@)</font><font color="#a9a9a9" size="2">.</font><font size="2">replace(</font><font color="#8b0000" size="2">"`n"</font><font color="#a9a9a9" size="2">,</font><font size="2"> </font><font color="#8b0000" size="2">""</font><font size="2">)</font><br><font color="#ff4500" size="2">$memory</font><font size="2"> </font><font color="#a9a9a9" size="2">=</font><font size="2"> </font><font color="#0000ff" size="2">new-object</font><font size="2"> </font><font color="#8a2be2" size="2">System.IO.MemoryStream</font><br><font color="#ff4500" size="2">$memory</font><font color="#a9a9a9" size="2">.</font><font size="2">write((</font><font color="#ff4500" size="2">$bytes</font><font color="#a9a9a9" size="2">=</font><font color="#008080" size="2">[System.Convert]</font><font color="#a9a9a9" size="2">::</font><font size="2">FromBase64String(</font><font color="#ff4500" size="2">$iconstring</font><font size="2">))</font><font color="#a9a9a9" size="2">,</font><font size="2"> </font><font color="#800080" size="2">0</font><font color="#a9a9a9" size="2">,</font><font size="2"> </font><font color="#ff4500" size="2">$bytes</font><font color="#a9a9a9" size="2">.</font><font size="2">length)</font><br><font color="#ff4500" size="2">$FORM</font><font color="#a9a9a9" size="2">.</font><font size="2">Icon </font><font color="#a9a9a9" size="2">=</font><font size="2"> </font><font color="#008080" size="2">[System.Drawing.Icon]</font><font color="#a9a9a9" size="2">::</font><font size="2">FromHandle((</font><font color="#0000ff" size="2">new-object</font><font size="2"> </font><font color="#8a2be2" size="2">System.Drawing.Bitmap</font><font size="2"> </font><font color="#000080" size="2">-argument</font><font size="2"> </font><font color="#ff4500" size="2">$memory</font><font size="2">)</font><font color="#a9a9a9" size="2">.</font><font size="2">GetHIcon())</font></p> <p align="center"><a href="http://bayes.co.uk/blog/image.axd?picture=iconbeforeandafter.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Before and After" src="http://bayes.co.uk/blog/image.axd?picture=iconbeforeandafter_thumb.jpg" width="145" height="137"></a> </p> <p align="center">Before and After</p>
http://www.bayes.co.uk/blog/post/Powershell-Adding-an-icon-to-a-form.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=fc22945d-aa50-4a17-9691-4ce999280d03 Wed, 11 Nov 2009 22:14:40 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=fc22945d-aa50-4a17-9691-4ce999280d03 26 http://www.bayes.co.uk/blog/trackback.axd?id=fc22945d-aa50-4a17-9691-4ce999280d03 http://www.bayes.co.uk/blog/post/Powershell-Adding-an-icon-to-a-form.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=fc22945d-aa50-4a17-9691-4ce999280d03

Powershell Xml Folder Tree Explorer

<p>Displaying the output of Get-DirAsXml in an explorer with Powershell.&nbsp; Although Powershell is a command line interface it can use forms to display output and get input. For an explorer the first thing we need is a treeview so we can use the System.Windows.Forms.TreeView control. Add it to a System.Windows.Forms.Form then recursively wander down the xml tree adding TreeNodes to it for all the nodes in the xml. Here is some code that will do that.</p> <p><!--style>.highlightbackground{ width: 100%; /*height: 100%;*/ overflow: auto; font-family: consolas, "Courier New", courier, mono; font-size: 12px; background-color: #eeeeee; color: #000000; padding: 2px 2px 2px 2px; white-space: nowrap; } .linenumberlist{border-left: solid 1px green;padding: 0px;} .linenumber{color: green;padding-left: 5px;} .foreground{color: #000000;} .command:color: #0000ff;} .commandparam{color: #000080;} .commandarg{color: #8a2be2;} .number{color: #800080;} .string{color: #8b0000;} .variable{color: #ff4500;} .type{color: #008080;} .operator{color: #a9a9a9;} .keyword{color: #00008b;} .comment{color: #006400;} .statementsep{color: #c86400;} .linecont{color: #c86400;}</style--></p> <div class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">Form-DisplayDir</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span>&nbsp;<span class="foreground">(</span><span class="type">[xml]</span><span class="variable">$XML</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">function</span>&nbsp;<span class="commandarg">DisplayDir_wander</span><span class="foreground">(</span><span class="variable">$el</span><span class="operator">,</span>&nbsp;<span class="variable">$tnode</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">foreach</span><span class="foreground">(</span><span class="variable">$e</span>&nbsp;<span class="keyword">in</span>&nbsp;<span class="variable">$el</span><span class="operator">.</span><span class="foreground">get_ChildNodes</span><span class="foreground">(</span><span class="foreground">)</span><span class="foreground">)</span><span class="foreground">{</span>&nbsp;<span class="comment">#|sort-object name){</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$tn</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Windows.Forms.TreeNode</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$tn</span><span class="operator">.</span><span class="foreground">Text</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$e</span><span class="operator">.</span><span class="foreground">name</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[Void]</span><span class="variable">$tnode</span><span class="operator">.</span><span class="foreground">Nodes</span><span class="operator">.</span><span class="foreground">add</span><span class="foreground">(</span>&nbsp;<span class="variable">$tn</span>&nbsp;<span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$e</span><span class="operator">.</span><span class="foreground">get_Name</span><span class="foreground">(</span><span class="foreground">)</span>&nbsp;<span class="operator">-eq</span>&nbsp;<span class="string">"folder"</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">DisplayDir_wander</span>&nbsp;<span class="foreground">(</span><span class="variable">$e</span><span class="foreground">)</span>&nbsp;<span class="foreground">(</span><span class="variable">$tn</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><br>&nbsp;&nbsp;&nbsp; <span class="variable">$FORM</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">Windows.Forms.Form</span>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">Size</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Size</span><span class="foreground">(</span><span class="number">300</span><span class="operator">,</span><span class="number">310</span><span class="foreground">)</span>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">text</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">"Form-DisplayDir"</span><br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$RESULT</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">""</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$TREEVIEW</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">windows.forms.TreeView</span>&nbsp;<br>&nbsp;&nbsp;&nbsp; <span class="variable">$TREEVIEW</span><span class="operator">.</span><span class="foreground">size</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Size</span><span class="foreground">(</span><span class="number">295</span><span class="operator">,</span><span class="number">269</span><span class="foreground">)</span>&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$TREEVIEW</span><span class="operator">.</span><span class="foreground">Anchor</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">"top, left, bottom, right"</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$TREEVIEW</span><span class="operator">.</span><span class="foreground">add_AfterSelect</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$RESULT</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$TREEVIEW</span><span class="operator">.</span><span class="foreground">SelectedNode</span><span class="operator">.</span><span class="foreground">FullPath</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$r</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$XML</span><span class="operator">.</span><span class="foreground">selectSingleNode</span><span class="foreground">(</span><span class="string">"/*"</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$tn</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Windows.Forms.TreeNode</span>&nbsp;<br>&nbsp;&nbsp;&nbsp; <span class="variable">$tn</span><span class="operator">.</span><span class="foreground">Text</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$r</span><span class="operator">.</span><span class="foreground">get_Name</span><span class="foreground">(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="command">DisplayDir_wander</span>&nbsp;<span class="foreground">(</span><span class="variable">$r</span><span class="foreground">)</span>&nbsp;<span class="foreground">(</span><span class="variable">$tn</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="type">[void]</span><span class="variable">$TREEVIEW</span><span class="operator">.</span><span class="foreground">Nodes</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$tn</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">Controls</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$TREEVIEW</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="type">[void]</span><span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">showdialog</span><span class="foreground">(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$RESULT</span><br><span class="foreground">}</span><br></div> <p>You can use it like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:d084b192-9f2c-41e1-b799-802a187786bf" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\Form-DisplayDir.ps1 # dot source the script<br>PS&gt; Form-DisplayDir (Get-DirAsXml test)<br></div></div> <p>It might be displayed like this.</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDir1.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDir1" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDir1_thumb.jpg" width="229" height="242"></a>&nbsp;</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:8731880c-47a1-4bcc-a51d-589fb35bee7b" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; Form-DisplayDir (Get-DirAsXml test -props @{Length=""})<br></div></div> <p>Will display this form with the file sizes in bytes shown.</p> <p align="center"><span style="font-size: smaller"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDir2.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDir2" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDir2_thumb.jpg" width="229" height="242"></a>&nbsp;</span></p> <p align="left">The next thing to do is add an event handler to the TreeView. I like to use the AfterSelect event rather than the Click event because it doesn't fire when you expand or collapse nodes.</p> <p><span style="color: #ff4500; font-size: smaller">$TREEVIEW</span><span style="color: #a9a9a9; font-size: smaller">.</span><span style="font-size: smaller">add_AfterSelect({<br>&nbsp;&nbsp;&nbsp; </span><span style="color: #ff4500; font-size: smaller">$RESULT</span><span style="font-size: smaller"> </span><span style="color: #a9a9a9; font-size: smaller">=</span><span style="font-size: smaller"> </span><span style="color: #ff4500; font-size: smaller">$TREEVIEW</span><span style="color: #a9a9a9; font-size: smaller">.</span><span style="font-size: smaller">SelectedNode</span><span style="color: #a9a9a9; font-size: smaller">.</span><span style="font-size: smaller">FullPath<br>})</span></p> <p>This bit of code can then be used as a simple folder/file selector. You could add the event to a Button and just stick $RESULT into the pipeline after the form closes.</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:54de1ca8-e039-40b7-a048-1b249ff9b018" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; Form-DisplayDir (Get-DirAsXml test) <br>root\test\test2\test.txt</div></div><br>or<br> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:8d9060ac-036c-4571-9b4e-b0891b6e7aab" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; Form-DisplayDir (Get-DirAsXml test) | SomeScriptThatNeedsAFilePath.ps1</div></div> <p>Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fForm-DisplayDir.zip">Form-DisplayDir.zip (621.00 bytes)</a></p> <p>The next thing to do is add a System.Windows.Forms.ListView control to display the files.</p> <div class="highlightbackground">&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">windows.forms.ListView</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Location</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Size</span><span class="foreground">(</span><span class="number">300</span><span class="operator">,</span>&nbsp;<span class="number">0</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Size</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Size</span><span class="foreground">(</span><span class="number">295</span><span class="operator">,</span><span class="number">269</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Anchor</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">"top, left, bottom, right"</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">View</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[System.Windows.Forms.View]</span><span class="operator">::</span><span class="foreground">Details</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">AllowColumnReorder</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$true</span><br>&nbsp;&nbsp;&nbsp; <span class="type">[void]</span><span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Columns</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="string">"Name"</span><span class="operator">,</span>&nbsp;<span class="number">-2</span><span class="operator">,</span>&nbsp;<span class="type">[windows.forms.HorizontalAlignment]</span><span class="operator">::</span><span class="foreground">left</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">foreach</span><span class="foreground">(</span><span class="variable">$att</span>&nbsp;<span class="keyword">in</span>&nbsp;<span class="variable">$XML</span><span class="operator">.</span><span class="foreground">SelectSingleNode</span><span class="foreground">(</span><span class="string">"//file"</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">)</span><span class="operator">.</span><span class="foreground">SelectNodes</span><span class="foreground">(</span><span class="string">"@*[not(name()='Name')]"</span><span class="foreground">)</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[void]</span><span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Columns</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$att</span><span class="operator">.</span><span class="foreground">get_Name</span><span class="foreground">(</span><span class="foreground">)</span><span class="operator">,</span>&nbsp;<span class="number">-2</span><span class="operator">,</span>&nbsp;<span class="type">[windows.forms.HorizontalAlignment]</span><span class="operator">::</span><span class="foreground">Right</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$TREEVIEW</span><span class="operator">.</span><span class="foreground">add_AfterSelect</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Items</span><span class="operator">.</span><span class="foreground">Clear</span><span class="foreground">(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$xmlnode</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$TREEVIEW</span><span class="operator">.</span><span class="foreground">SelectedNode</span><span class="operator">.</span><span class="foreground">Tag</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">foreach</span><span class="foreground">(</span><span class="variable">$child</span>&nbsp;<span class="keyword">in</span>&nbsp;<span class="variable">$xmlnode</span><span class="operator">.</span><span class="foreground">get_ChildNodes</span><span class="foreground">(</span><span class="foreground">)</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$item</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">windows.forms.ListViewItem</span><span class="foreground">(</span><span class="variable">$child</span><span class="operator">.</span><span class="foreground">Name</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">foreach</span><span class="foreground">(</span><span class="variable">$column</span>&nbsp;<span class="keyword">in</span>&nbsp;<span class="foreground">(</span><span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Columns</span><span class="operator">|</span><span class="command">where</span><span class="foreground">{</span><span class="variable">$_</span><span class="operator">.</span><span class="foreground">Text</span>&nbsp;<span class="operator">-ne</span>&nbsp;<span class="string">"Name"</span><span class="foreground">}</span><span class="foreground">)</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$child</span><span class="operator">.</span><span class="foreground">(</span><span class="variable">$column</span><span class="operator">.</span><span class="foreground">Text</span><span class="foreground">)</span>&nbsp;<span class="operator">-ne</span>&nbsp;<span class="variable">$null</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$item</span><span class="operator">.</span><span class="foreground">SubItems</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$child</span><span class="operator">.</span><span class="foreground">(</span><span class="variable">$column</span><span class="operator">.</span><span class="foreground">Text</span><span class="foreground">)</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Items</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$item</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">Controls</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$LISTVIEW</span><span class="foreground">)</span><br></div> <p>The TreeView AfterSelect event has been changed to populate the ListView.</p> <p>To make it look a bit more like Explorer you probably want to add a couple more columns to the xml</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:61830c4a-5498-49e1-bf1f-a49d03f88dc1" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; Form-DisplayDirExp (Get-DirAsXml test -props @{Length="";LastWriteTime=""})</div></div> <p>It might be displayed like this</p> <p align="center">&nbsp;<a href="http://www.bayes.co.uk/blog/image.axd?picture=FormDisplayDirExp12.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="FormDisplayDirExp12" src="http://www.bayes.co.uk/blog/image.axd?picture=FormDisplayDirExp12_thumb.jpg" width="244" height="121"></a></p> <p style="text-align: left">Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fForm-DisplayDirExp.zip">Form-DisplayDirExp.zip (953.00 bytes)</a></p> <p>It is getting there but it is a bit confusing without icons, especially for the folders. There are a few different ways of doing this. You could create a System.Windows.Forms.ImageList object and add images to that then assign it to the $TREEVIEW.ImageList property but it gets quite labour intensive to make a lot of little icons. You could have just 2 icons, one for folders and one for files. So add some code like this</p> <div class="highlightbackground"><span class="variable">$ImageList</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">New-Object</span>&nbsp;<span class="commandarg">System.Windows.Forms.ImageList</span>&nbsp;<br><span class="variable">$imageList</span><span class="operator">.</span><span class="foreground">Images</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="type">[System.Drawing.Bitmap]</span><span class="operator">::</span><span class="foreground">FromFile</span><span class="foreground">(</span><span class="string">"folder.bmp"</span><span class="foreground">)</span><span class="foreground">)</span><br><span class="variable">$imageList</span><span class="operator">.</span><span class="foreground">Images</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="type">[System.Drawing.Bitmap]</span><span class="operator">::</span><span class="foreground">FromFile</span><span class="foreground">(</span><span class="string">"file.bmp"</span><span class="foreground">)</span><span class="foreground">)</span><br><span class="variable">$TREEVIEW</span><span class="operator">.</span><span class="foreground">ImageList</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$ImageList</span>&nbsp;<br><span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">SmallImageList</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$ImageList</span>&nbsp;<br></div> <p>It might be displayed like this</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExp2_1.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDirExp2" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExp2_thumb_1.jpg" width="244" height="124"></a></p> <p>&nbsp;</p> <p>The best way to add icons is to use the SystemImageList or Shell Icon Cache. It is used everywhere and if you are using TreeView and ListView controls then one would think there would be a simple way of saying Hey! TreeView."UseTheEffingSystemImageList" But it is not that simple. You have to get down to the nitty gritty with System.Runtime.InteropServices SHGetFileInfo and SendMessage. So I wrapped all that 'c++ twitter' up in a file that you can just 'dot source' and then use the 2 methods (SetSystemImageListHandle, GetSystemImageListIndex) it contains.</p> <p>int SetSystemImageListHandle(Control, int Size) sets the ImageList for the TreeView/ListView control to the SystemImageList and the Size to large or small (0, 1).</p> <p>int GetSystemImageListIndex(string Filename, boolean Dir, int Size) gets the image index for the filename. Dir is a boolean indicating if it is a Folder and Size is large or small (0, 1).</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fImageListHandle.zip">ImageListHandle.zip (2.19 kb)</a></p> <p>Here are some code snippets.</p> <div class="highlightbackground"><span class="operator">.</span>&nbsp;<span class="command">.\ImageListHandle.ps1</span><br><span class="variable">$SHGFI_SMALLICON</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="number">1</span><span class="statementsep">;</span>&nbsp;<span class="variable">$SHGFI_LARGEICON</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="number">0</span><br><span class="variable">$LISTVIEW</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Windows.Forms.ListView</span><br><span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">Controls</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$LISTVIEW</span><span class="foreground">)</span><br><span class="type">[void]</span><span class="type">[cjb.Shell32]</span><span class="operator">::</span><span class="foreground">SetSystemImageListHandle</span><span class="foreground">(</span><span class="variable">$LISTVIEW</span><span class="operator">,</span>&nbsp;<span class="variable">$SHGFI_SMALLICON</span><span class="foreground">)</span><br><span class="variable">$TREEVIEW</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Windows.Forms.TreeView</span><br><span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">Controls</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$TREEVIEW</span><span class="foreground">)</span><br><span class="type">[void]</span><span class="type">[cjb.Shell32]</span><span class="operator">::</span><span class="foreground">SetSystemImageListHandle</span><span class="foreground">(</span><span class="variable">$TREEVIEW</span><span class="operator">,</span>&nbsp;<span class="variable">$SHGFI_SMALLICON</span><span class="foreground">)</span><br><span class="variable">$tn</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Windows.Forms.TreeNode</span><br><span class="variable">$tn</span><span class="operator">.</span><span class="foreground">ImageIndex</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$tn</span><span class="operator">.</span><span class="foreground">SelectedImageIndex</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[cjb.Shell32]</span><span class="operator">::</span><span class="foreground">GetSystemImageListIndex</span><span class="foreground">(</span><span class="variable">$e</span><span class="operator">.</span><span class="foreground">Name</span><span class="operator">,</span>&nbsp;<span class="foreground">(</span><span class="variable">$e</span><span class="operator">.</span><span class="foreground">get_Name</span><span class="foreground">(</span><span class="foreground">)</span>&nbsp;<span class="operator">-eq</span>&nbsp;<span class="string">"folder"</span><span class="foreground">)</span><span class="operator">,</span>&nbsp;<span class="variable">$SHGFI_SMALLICON</span><span class="foreground">)</span><br><span class="variable">$idx</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[cjb.Shell32]</span><span class="operator">::</span><span class="foreground">GetSystemImageListIndex</span><span class="foreground">(</span><span class="variable">$n</span><span class="operator">.</span><span class="foreground">Name</span><span class="operator">,</span>&nbsp;<span class="foreground">(</span><span class="variable">$n</span><span class="operator">.</span><span class="foreground">get_Name</span><span class="foreground">(</span><span class="foreground">)</span>&nbsp;<span class="operator">-eq</span>&nbsp;<span class="string">"folder"</span><span class="foreground">)</span><span class="operator">,</span>&nbsp;<span class="variable">$SHGFI_SMALLICON</span><span class="foreground">)</span><br><span class="variable">$item</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">windows.forms.ListViewItem</span><span class="foreground">(</span><span class="variable">$n</span><span class="operator">.</span><span class="foreground">Name</span><span class="operator">,</span><span class="variable">$idx</span><span class="foreground">)</span><br></div> <p>For this to work properly the control must be added to the form before SetSystemImageListHandle is called.</p> <p>Here is the version that uses the SystemImageList</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fForm-DisplayDirExpIcons.zip">Form-DisplayDirExpIcons.zip (1.09 kb)</a></p> <p>It might be displayed like this</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExp3.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDirExp3" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExp3_thumb.jpg" width="244" height="121"></a></p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fImageListHandle.zip"></a></p> <p>A useful thing to set on the ListView control is AutoResizeColumns. This can have one of two values, HeaderSize or ColumnContent and resizes the columns depending on the width of the text.</p> <p><span style="color: #ff4500; font-size: smaller">$LISTVIEW</span><span style="color: #a9a9a9; font-size: smaller">.</span><span style="font-size: smaller">AutoResizeColumns(</span><span style="color: #008080; font-size: smaller">[Windows.Forms.ColumnHeaderAutoResizeStyle]</span><span style="color: #a9a9a9; font-size: smaller">::</span><span style="font-size: smaller">HeaderSize)</span></p> <p>Another is AllowColumnReorder. This allows you to move the columns around as you like</p> <p><span style="color: #ff4500; font-size: smaller">$LISTVIEW</span><span style="color: #a9a9a9; font-size: smaller">.</span><span style="font-size: smaller">AllowColumnReorder </span><span style="color: #a9a9a9; font-size: smaller">=</span><span style="font-size: smaller"> </span><span style="color: #ff4500; font-size: smaller">$true</span></p> <p>With all of the attributes that you can have in the xml it might be handy to specify which columns you want displayed in the ListView. This can be done by passing an array of attribute names that will be displayed as columns. Here Get-DirAsXml adds 9 attributes (Name + 2props + 6extendedProps)</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:6392ab6d-87ab-40cd-80b7-fa7960e46187" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; Form-DisplayDirExp (Get-DirAsXml test -props @{Length="";LastWriteTime=""} -ExtendedProps @{Title=""; Subject=""; Author=""; Category=""; Keywords=""; Comments=""}) <u>-columns @("Name", "Length", "LastWriteTime")</u></div></div> <p>So instead of displaying all 9 file properties it will only display Name, Length and LastWriteTime in that order. But supposing you DO want to see the other file properties? You could add a third pane to the Explorer</p> <div class="highlightbackground"><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW2</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">windows.forms.ListView</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">Controls</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$LISTVIEW2</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW2</span><span class="operator">.</span><span class="foreground">Location</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Size</span><span class="foreground">(</span><span class="number">600</span><span class="operator">,</span>&nbsp;<span class="number">0</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW2</span><span class="operator">.</span><span class="foreground">Size</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Size</span><span class="foreground">(</span><span class="number">295</span><span class="operator">,</span><span class="number">269</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW2</span><span class="operator">.</span><span class="foreground">Anchor</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">"top, bottom, right"</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW2</span><span class="operator">.</span><span class="foreground">View</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[System.Windows.Forms.View]</span><span class="operator">::</span><span class="foreground">Details</span><br>&nbsp;&nbsp;&nbsp; <span class="type">[void]</span><span class="variable">$LISTVIEW2</span><span class="operator">.</span><span class="foreground">Columns</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="string">"Name"</span><span class="operator">,</span>&nbsp;<span class="number">-2</span><span class="operator">,</span>&nbsp;<span class="type">[windows.forms.HorizontalAlignment]</span><span class="operator">::</span><span class="foreground">Left</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="type">[void]</span><span class="variable">$LISTVIEW2</span><span class="operator">.</span><span class="foreground">Columns</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="string">"Value"</span><span class="operator">,</span>&nbsp;<span class="number">-2</span><span class="operator">,</span>&nbsp;<span class="type">[windows.forms.HorizontalAlignment]</span><span class="operator">::</span><span class="foreground">Right</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">add_ItemActivate</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW2</span><span class="operator">.</span><span class="foreground">Items</span><span class="operator">.</span><span class="foreground">Clear</span><span class="foreground">(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$xmlnode</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">SelectedItems</span><span class="operator">[</span><span class="number">0</span><span class="operator">]</span><span class="operator">.</span><span class="foreground">Tag</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">foreach</span><span class="foreground">(</span><span class="variable">$att</span>&nbsp;<span class="keyword">in</span>&nbsp;<span class="variable">$xmlnode</span><span class="operator">.</span><span class="foreground">Attributes</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$item</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">windows.forms.ListViewItem</span><span class="foreground">(</span><span class="variable">$att</span><span class="operator">.</span><span class="foreground">get_Name</span><span class="foreground">(</span><span class="foreground">)</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$item</span><span class="operator">.</span><span class="foreground">SubItems</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$att</span><span class="operator">.</span><span class="foreground">Value</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW2</span><span class="operator">.</span><span class="foreground">Items</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$item</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp; </div> <p>It might be displayed like this&nbsp; </p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpIcon3Pane.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDirExpIcon3Pane" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpIcon3Pane_thumb.jpg" width="244" height="83"></a></p> <p>Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fForm-DisplayDirExpIcons3Pane.zip">Form-DisplayDirExpIcons3Pane.zip (1.27 kb)</a></p> <p>You could set the ToolTipText on the ListViewItems. First set <span style="font-size: smaller">ShowItemToolTips </span>to true. This must be done before you set the SystemImageList handle if you are using icons.</p> <p><span style="color: #ff4500; font-size: smaller">$LISTVIEW</span><span style="color: #a9a9a9; font-size: smaller">.</span><span style="font-size: smaller">ShowItemToolTips </span><span style="color: #a9a9a9; font-size: smaller">=</span><span style="font-size: smaller"> </span><span style="color: #ff4500; font-size: smaller">$true</span></p> <p>Then build up your own ToolTipText or if you specified -ExtendedProps @{InfoTip=""} on Get-DirAsXml then you can use it as you populate the ListView control</p> <p><span style="color: #ff4500; font-size: smaller">$item</span><span style="color: #a9a9a9; font-size: smaller">.</span><span style="font-size: smaller">ToolTipText </span><span style="color: #a9a9a9; font-size: smaller">=</span><span style="font-size: smaller"> </span><span style="color: #ff4500; font-size: smaller">$child</span><span style="color: #a9a9a9; font-size: smaller">.</span><span style="font-size: smaller">InfoTip</span></p> <p>This might be displayed like this (with cursor)</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpToolTip.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDirExpToolTip" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpToolTip_thumb.jpg" width="244" height="241"></a></p> <p>Adding a context menu to the ListView is quite easy.</p> <div class="highlightbackground"><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">ContextMenu</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$cm</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">Windows.Forms.ContextMenu</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$mi</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$cm</span><span class="operator">.</span><span class="foreground">MenuItems</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="string">"Do Thing One"</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$mi</span><span class="operator">.</span><span class="foreground">add_Click</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$XMLNODE</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$LISTVIEWNODE</span><span class="operator">.</span><span class="foreground">Tag</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">Write-Host</span>&nbsp;<span class="string">"Thing One invoked on $LISTVIEWNODE."</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$mi</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$cm</span><span class="operator">.</span><span class="foreground">MenuItems</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="string">"Do Thing Two"</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$mi</span><span class="operator">.</span><span class="foreground">add_Click</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$XMLNODE</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$LISTVIEWNODE</span><span class="operator">.</span><span class="foreground">Tag</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">Write-Host</span>&nbsp;<span class="string">"Thing Two invoked on $LISTVIEWNODE."</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">add_MouseDown</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$_</span><span class="operator">.</span><span class="foreground">Button</span>&nbsp;<span class="operator">-eq</span>&nbsp;<span class="type">[Windows.Forms.MouseButtons]</span><span class="operator">::</span><span class="foreground">Right</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEWNODE</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">GetItemAt</span><span class="foreground">(</span><span class="variable">$_</span><span class="operator">.</span><span class="foreground">X</span><span class="operator">,</span>&nbsp;<span class="variable">$_</span><span class="operator">.</span><span class="foreground">Y</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="keyword">else</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEWNODE</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$null</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br></div> <p>This might be displayed like this</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpMenu.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDirExpMenu" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpMenu_thumb.jpg" width="244" height="122"></a></p> <p align="left">On the Host console you will see</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpMenuO.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDirExpMenuO" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpMenuO_thumb.jpg" width="244" height="18"></a></p> <p align="left">Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fForm-DisplayDirExpMenu.zip">Form-DisplayDirExpMenu.zip (1.29 kb)</a></p> <p>With all those ExtendedProperties you can get from Get-DirAsXml a search functionality is mighty useful. Here is some code to add an XPath search to the explorer. Any valid XPath can be used such as //file[contains(@Author, 'Chr')]&nbsp; or //file[contains(@BitRate, '44')]. A find duplicate file names: //file[@Name = preceding::file/@Name]. See <a href="http://www.bayes.co.uk/blog/post/Powershell-Translets-C-Script-Checksum.aspx">this previous entry</a> for how to add a Checksum attribute then find duplicate files //file[@Checksum = preceding::file/@Checksum].</p> <div class="highlightbackground">&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$SEARCHBOX</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">windows.forms.TextBox</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$SEARCHBOX</span><span class="operator">.</span><span class="foreground">Location</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Point</span><span class="foreground">(</span><span class="number">85</span><span class="operator">,</span>&nbsp;<span class="number">275</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$SEARCHBOX</span><span class="operator">.</span><span class="foreground">Size</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Size</span><span class="foreground">(</span><span class="number">490</span><span class="operator">,</span><span class="number">20</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$SEARCHBOX</span><span class="operator">.</span><span class="foreground">Anchor</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">"left, bottom, right"</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">Controls</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$SEARCHBOX</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$BUTTON</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">windows.forms.button</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$BUTTON</span><span class="operator">.</span><span class="foreground">Location</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Point</span><span class="foreground">(</span><span class="number">10</span><span class="operator">,</span>&nbsp;<span class="number">275</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$BUTTON</span><span class="operator">.</span><span class="foreground">Anchor</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">"left, bottom"</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$BUTTON</span><span class="operator">.</span><span class="foreground">Text</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">"Search"</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$BUTTON</span><span class="operator">.</span><span class="foreground">add_Click</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Items</span><span class="operator">.</span><span class="foreground">Clear</span><span class="foreground">(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$nodes</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$XML</span><span class="operator">.</span><span class="foreground">SelectNodes</span><span class="foreground">(</span><span class="variable">$SEARCHBOX</span><span class="operator">.</span><span class="foreground">Text</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">foreach</span><span class="foreground">(</span><span class="variable">$child</span>&nbsp;<span class="keyword">in</span>&nbsp;<span class="variable">$nodes</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$idx</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[cjb.Shell32]</span><span class="operator">::</span><span class="foreground">GetSystemImageListIndex</span><span class="foreground">(</span><span class="variable">$child</span><span class="operator">.</span><span class="foreground">Name</span><span class="operator">,</span>&nbsp;<span class="foreground">(</span><span class="variable">$child</span><span class="operator">.</span><span class="foreground">get_Name</span><span class="foreground">(</span><span class="foreground">)</span>&nbsp;<span class="operator">-eq</span>&nbsp;<span class="string">"folder"</span><span class="foreground">)</span><span class="operator">,</span>&nbsp;<span class="variable">$SHGFI_SMALLICON</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$item</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">windows.forms.ListViewItem</span><span class="foreground">(</span><span class="variable">$child</span><span class="operator">.</span><span class="foreground">Name</span><span class="operator">,</span>&nbsp;<span class="variable">$idx</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$item</span><span class="operator">.</span><span class="foreground">Tag</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$child</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$item</span><span class="operator">.</span><span class="foreground">ToolTipText</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$child</span><span class="operator">.</span><span class="foreground">InfoTip</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">foreach</span><span class="foreground">(</span><span class="variable">$column</span>&nbsp;<span class="keyword">in</span>&nbsp;<span class="foreground">(</span><span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Columns</span><span class="operator">|</span><span class="command">where</span><span class="foreground">{</span><span class="variable">$_</span><span class="operator">.</span><span class="foreground">Text</span>&nbsp;<span class="operator">-ne</span>&nbsp;<span class="string">"Name"</span><span class="foreground">}</span><span class="foreground">)</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$child</span><span class="operator">.</span><span class="foreground">(</span><span class="variable">$column</span><span class="operator">.</span><span class="foreground">Text</span><span class="foreground">)</span>&nbsp;<span class="operator">-ne</span>&nbsp;<span class="variable">$null</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$item</span><span class="operator">.</span><span class="foreground">SubItems</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$child</span><span class="operator">.</span><span class="foreground">(</span><span class="variable">$column</span><span class="operator">.</span><span class="foreground">Text</span><span class="foreground">)</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="keyword">else</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$item</span><span class="operator">.</span><span class="foreground">SubItems</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="string">""</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">Items</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$item</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">AutoResizeColumns</span><span class="foreground">(</span><span class="type">[Windows.Forms.ColumnHeaderAutoResizeStyle]</span><span class="operator">::</span><span class="foreground">ColumnContent</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="variable">$FORM</span><span class="operator">.</span><span class="foreground">Controls</span><span class="operator">.</span><span class="foreground">Add</span><span class="foreground">(</span><span class="variable">$BUTTON</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <br></div> <p>It might be displayed like this (with cursor)</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpSearch_1.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDirExpSearch" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpSearch_thumb_1.jpg" width="244" height="109"></a></p> <p>Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fForm-DisplayDirExpSearch.zip">Form-DisplayDirExpSearch.zip (1.26 kb)</a></p> <p>Another thing you might want to do is drag'n'drop. I will go back to the 3 pane solution but with a ListView in the middle and a TreeView on either side. The drag'n'drop rule is simple. Things can be dragged only from the ListView to the right side TreeView.</p> <div class="highlightbackground">&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$LISTVIEW</span><span class="operator">.</span><span class="foreground">add_ItemDrag</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">param</span><span class="foreground">(</span><span class="variable">$sender</span><span class="operator">,</span>&nbsp;<span class="variable">$e</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$nodes</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">@(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">foreach</span><span class="foreground">(</span><span class="variable">$lvi</span>&nbsp;<span class="keyword">in</span>&nbsp;<span class="variable">$sender</span><span class="operator">.</span><span class="foreground">SelectedItems</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$nodes</span>&nbsp;<span class="operator">+=</span>&nbsp;<span class="variable">$lvi</span><span class="operator">.</span><span class="foreground">Tag</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$sender</span><span class="operator">.</span><span class="foreground">DoDragDrop</span><span class="foreground">(</span><span class="variable">$nodes</span><span class="operator">,</span>&nbsp;<span class="type">[System.Windows.Forms.DragDropEffects]</span><span class="operator">::</span><span class="foreground">Link</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="variable">$TREEVIEW2</span><span class="operator">.</span><span class="foreground">add_DragDrop</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">param</span><span class="foreground">(</span><span class="variable">$sender</span><span class="operator">,</span>&nbsp;<span class="variable">$e</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$point</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Drawing.Point</span>&nbsp;<span class="commandparam">-ArgumentList</span>&nbsp;<span class="foreground">@(</span><span class="variable">$e</span><span class="operator">.</span><span class="foreground">X</span><span class="operator">,</span>&nbsp;<span class="variable">$e</span><span class="operator">.</span><span class="foreground">Y</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$targetPoint</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$sender</span><span class="operator">.</span><span class="foreground">PointToClient</span><span class="foreground">(</span><span class="variable">$point</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$dropnode</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$sender</span><span class="operator">.</span><span class="foreground">GetNodeAt</span><span class="foreground">(</span><span class="variable">$targetPoint</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$dropnode</span><span class="operator">.</span><span class="foreground">Tag</span><span class="operator">.</span><span class="foreground">get_Name</span><span class="foreground">(</span><span class="foreground">)</span>&nbsp;<span class="operator">-eq</span>&nbsp;<span class="string">"folder"</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$nodes</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$e</span><span class="operator">.</span><span class="foreground">Data</span><span class="operator">.</span><span class="foreground">GetData</span><span class="foreground">(</span><span class="string">"System.Object[]"</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">foreach</span><span class="foreground">(</span><span class="variable">$n</span>&nbsp;<span class="keyword">in</span>&nbsp;<span class="variable">$nodes</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$newnode</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$XML2</span><span class="operator">.</span><span class="foreground">ImportNode</span><span class="foreground">(</span><span class="variable">$n</span><span class="operator">,</span>&nbsp;<span class="variable">$true</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$dropnode</span><span class="operator">.</span><span class="foreground">Tag</span><span class="operator">.</span><span class="foreground">AppendChild</span><span class="foreground">(</span><span class="variable">$newnode</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$dropnode</span><span class="operator">.</span><span class="foreground">Nodes</span><span class="operator">.</span><span class="foreground">Clear</span><span class="foreground">(</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">DisplayDir_wander</span>&nbsp;<span class="foreground">(</span><span class="variable">$dropnode</span><span class="operator">.</span><span class="foreground">Tag</span><span class="foreground">)</span>&nbsp;<span class="foreground">(</span><span class="variable">$dropnode</span><span class="foreground">)</span>&nbsp;<span class="foreground">(</span><span class="variable">$true</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br></div> <p>It might be displayed like this (without cursor)</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpDragDrop.jpg"><img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="Form-DisplayDirExpDragDrop" src="http://www.bayes.co.uk/blog/image.axd?picture=Form-DisplayDirExpDragDrop_thumb.jpg" width="244" height="92"></a>&nbsp;</p> <p>So imagine that the left is a list of all files in a tree, on the right are groups and topics in a knowledgebase. It might be a movie or mp3 library with moods or genres. It needs human interaction to decide how the resulting xml is layed out and what it contains. Here is a possibility, it takes the usual as input plus another xml that it creates on the fly. The output when the form is closed is sent to the T-Dax2Wpl translet to create a Windows Media Player playlist. Or it might be an inventory list for a software release and all the resulting files are copied to an output media.</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:1cfdb97e-6740-4f21-bd48-957d4629a179" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; Form-DisplayDirExp (Get-DirAsXml test -props @{Length="";LastWriteTime=""} -ExtendedProps @{Title="";Subject=""; Author="";Category="";Keywords=""; Comments=""}) -columns @("Name", "Length", "LastWriteTime") <u>-xml2 ([xml]'&lt;root&gt;&lt;folder Name="Knowledge"&gt;&lt;folder Name="Topic" /&gt;&lt;folder Name="Group" /&gt;&lt;/folder&gt;&lt;/root&gt;') | T-Dax2Wpl</u></div></div> <p>Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fForm-DisplayDirExpDragDrop.zip">Form-DisplayDirExpDragDrop.zip (1.72 kb)</a></p>
http://www.bayes.co.uk/blog/post/Powershell-Xml-Folder-Tree-Explorer.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=c61fdb3d-f57e-4920-86c3-aae23b69aeb2 Wed, 11 Nov 2009 22:13:18 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=c61fdb3d-f57e-4920-86c3-aae23b69aeb2 198 http://www.bayes.co.uk/blog/trackback.axd?id=c61fdb3d-f57e-4920-86c3-aae23b69aeb2 http://www.bayes.co.uk/blog/post/Powershell-Xml-Folder-Tree-Explorer.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=c61fdb3d-f57e-4920-86c3-aae23b69aeb2

Powershell Translets TTAF to SMI M3

<p>Here is a&nbsp; translet that will transform Timed Text (TT) Authoring Format 1.0&nbsp; to Microsoft Synchronized Accessible Media Interchange (SAMI). This one allows you to specify a TimeShift value in milliseconds to the transform. It also does better subtitle colouring.</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:186a7b1c-a625-4d3f-8cc8-aee482a42170" class="wlWriterSmartContent"> <div class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">T-TtafToSmi</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span>&nbsp;<span class="foreground">(</span>&nbsp; <span class="type">[xml]</span><span class="variable">$inxml</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">,</span><span class="type">[int]</span><span class="variable">$TimeShift</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="number">0</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">BEGIN</span>&nbsp;<span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\invoke-transform.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"> xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>"<span class="attribute"><br>xmlns:t</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1</span>"<span class="attribute"><br>xmlns</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1</span>"<span class="attribute"><br>xmlns:ttp</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1#parameter</span>"<span class="attribute"><br>xmlns:tts</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1#style</span>"<span class="attribute"><br>xmlns:ttm</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1#metadata</span>"<span class="attribute"><br>xmlns:msxsl</span>="<span class="attributetext">urn:schemas-microsoft-com:xslt</span>"<span class="attribute"><br>xmlns:cjb</span>="<span class="attributetext">http://www.bayes.co.uk/script</span>" <span class="attribute">version</span>="<span class="attributetext">1.0</span>" <span class="attribute">exclude-result-prefixes</span>="<span class="attributetext">#default t ttp tts ttm msxsl cjb</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">param</span> <span class="attribute">name</span>="<span class="attributetext">TimeShift</span>" <span class="attribute">select</span>="<span class="attributetext">0</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">output</span> <span class="attribute">encoding</span>="<span class="attributetext">utf-8</span>" <span class="attribute">indent</span>="<span class="attributetext">yes</span>" <span class="attribute">method</span>="<span class="attributetext">xml</span>" <span class="attribute">omit-xml-declaration</span>="<span class="attributetext">yes</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">msxsl</span>:<span class="element">script</span> <span class="attribute">language</span>="<span class="attributetext">C#</span>" <span class="attribute">implements-prefix</span>="<span class="attributetext">cjb</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public double getMilliseconds(string time)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (string.IsNullOrEmpty(time) ? 0 : TimeSpan.Parse(time).TotalMilliseconds);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string hyphenate(string str){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text.StringBuilder sb = new Text.StringBuilder("", 100);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (char c in str){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (char.IsUpper(c)){sb.Append("-");sb.Append(char.ToLower(c));}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else{sb.Append(c);}}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return sb.ToString();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">msxsl</span>:<span class="element">script</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">default-style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">for-each</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:styling/t:style[last()]</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">sort</span> <span class="attribute">order</span>="<span class="attributetext">ascending</span>" <span class="attribute">select</span>="<span class="attributetext">count(@tts:*)</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@id</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">for-each</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">variable</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">default-class</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/@xml:lang</span>" /&gt;<span class="text">cc<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">variable</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:tt</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">SAMI</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">HEAD</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">TITLE</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:metadata/ttm:title</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">TITLE</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">comment</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Copyright </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:metadata/ttm:copyright</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">comment</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/comment()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">STYLE</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">comment</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text-align: center;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-family: arial, sans-serif;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-weight: normal;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color: white;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-size: 16pt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:styling/t:style[@id=$default-style]/@tts:*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">$default-class</span>" /&gt;<span class="text"> {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text-align: center;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-family: arial, sans-serif;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-weight: normal;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color: white;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-size: 16pt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:styling/t:style[@id=$default-style]/@tts:*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name: </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/@xml:lang</span>" /&gt;<span class="text"> Subtitles;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lang: </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/@xml:lang</span>" /&gt;<span class="text">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SAMI_Type: CC;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">comment</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">STYLE</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">HEAD</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:body</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">SAMI</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:body</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">BODY</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">BODY</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:body/t:div</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:p</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">start</span>" <span class="attribute">select</span>="<span class="attributetext">cjb:getMilliseconds(string(@begin)) + $TimeShift</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">end</span>" <span class="attribute">select</span>="<span class="attributetext">cjb:getMilliseconds(string(@end)) + $TimeShift</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">following-start</span>" <span class="attribute">select</span>="<span class="attributetext">cjb:getMilliseconds(string(following-sibling::t:p/@begin)) + $TimeShift</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Sync</span> <span class="attribute">START</span>="<span class="attributetext">{$start}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">p</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">@style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">class</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">$default-class</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">span</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">@style=$default-style and @tts:*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">span</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@tts:*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">span</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">@style!=$default-style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:styling/t:style[@id=current()/@style]/@tts:*|@tts:*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">span</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">p</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Sync</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">$end &amp;lt; ($following-start - 10)</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Sync</span> <span class="attribute">START</span>="<span class="attributetext">{$end}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">p</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">nonbreakingspace</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">p</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Sync</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">@tts:*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">cjb:hyphenate(local-name())</span>" /&gt;<span class="text">:</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">.</span>" /&gt;<span class="text">;<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">@tts:fontFamily</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">cjb:hyphenate(local-name())</span>" /&gt;<span class="text">:</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">cjb:hyphenate(.)</span>" /&gt;<span class="text">;<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">@tts:fontSize</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">cjb:hyphenate(local-name())</span>" /&gt;<span class="text">:</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">.</span>" /&gt;<span class="text"> pt;<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">element</span> <span class="attribute">name</span>="<span class="attributetext">{local-name(.)}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">@tts:*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@tts:*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*[namespace-uri()!='http://www.w3.org/2006/10/ttaf1#style']</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">element</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">text()</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">@*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">{local-name()}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">.</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div><span class="string">'@</span><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">PROCESS</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$_</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$_</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-arguments</span>&nbsp;<span class="foreground">@{</span><span class="foreground">TimeShift</span><span class="operator">=</span><span class="variable">$TimeShift</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$result</span><span class="operator">.</span><span class="foreground">replace</span><span class="foreground">(</span><span class="string">" xmlns=`"http://www.w3.org/2006/10/ttaf1`""</span><span class="operator">,</span>&nbsp;<span class="string">""</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$result</span><span class="operator">.</span><span class="foreground">replace</span><span class="foreground">(</span><span class="string">"&lt;nonbreakingspace /&gt;"</span><span class="operator">,</span>&nbsp;<span class="string">"&amp;nbsp;"</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="command">END</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$inxml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-arguments</span>&nbsp;<span class="foreground">@{</span><span class="foreground">TimeShift</span><span class="operator">=</span><span class="variable">$TimeShift</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$result</span><span class="operator">.</span><span class="foreground">replace</span><span class="foreground">(</span><span class="string">" xmlns=`"http://www.w3.org/2006/10/ttaf1`""</span><span class="operator">,</span>&nbsp;<span class="string">""</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$result</span><span class="operator">.</span><span class="foreground">replace</span><span class="foreground">(</span><span class="string">"&lt;nonbreakingspace /&gt;"</span><span class="operator">,</span>&nbsp;<span class="string">"&amp;nbsp;"</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><span class="foreground">}</span><br></div></div> <p></p> <p>The replaces on the $result string look like a bit of a hack but they do need to be there for reasons that are very long to explain.</p> <p>It can be used like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:cbb93dec-59bd-48b6-89a4-287509edd1e0" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\T-TtafToSmiM3.ps1 # dot source this file<br>PS&gt; T-TtafToSmi [xml](gc ttaf.xml) -T 1000| sc -encoding ascii<br></div></div> <p>or</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:839fa31a-9cce-4940-b1df-e59220a9ceab" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\T-TtafToSmiM3.ps1 # dot source this file<br>PS&gt; [xml](gc .\ttaf.xml) | T-TtafToSmi -T 1000 | sc -encoding ascii<br></div></div> <p>The -T 1000 will shift the subtitle forward by 1 second. A value of -T -1000 will shift the subtitle backward by 1 second.</p> <p>Here is the code</p> <p>&nbsp;<a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fT-TtafToSmiM3.zip">T-TtafToSmiM3.zip (2.50 kb)</a></p>
http://www.bayes.co.uk/blog/post/Powershell-Translets-TTAF-to-SMI-M3.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=dc46607e-a9c2-4994-9ff5-51623fd4d158 Sun, 8 Nov 2009 21:47:27 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=dc46607e-a9c2-4994-9ff5-51623fd4d158 3 http://www.bayes.co.uk/blog/trackback.axd?id=dc46607e-a9c2-4994-9ff5-51623fd4d158 http://www.bayes.co.uk/blog/post/Powershell-Translets-TTAF-to-SMI-M3.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=dc46607e-a9c2-4994-9ff5-51623fd4d158

Powershell Translets TTAF to SMI M1

<p>Here is a&nbsp; translet that will transform Timed Text (TT) Authoring Format 1.0&nbsp; to Microsoft Synchronized Accessible Media Interchange (SAMI). This one is quite simple. All text is the same colour. Not much different from SRT format really.</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:89179fa6-b710-4611-b0b6-0b469ae4d8b1" class="wlWriterSmartContent"> <div class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">T-TtafToSmi</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">BEGIN</span>&nbsp;<span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\invoke-transform.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"> xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>"<span class="attribute"><br>xmlns:t</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1</span>"<span class="attribute"><br>xmlns</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1</span>"<span class="attribute"><br>xmlns:ttp</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1#parameter</span>"<span class="attribute"><br>xmlns:tts</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1#style</span>"<span class="attribute"><br>xmlns:ttm</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1#metadata</span>"<span class="attribute"><br>xmlns:msxsl</span>="<span class="attributetext">urn:schemas-microsoft-com:xslt</span>"<span class="attribute"><br>xmlns:cjb</span>="<span class="attributetext">http://www.bayes.co.uk/script</span>"<br><span class="attribute">version</span>="<span class="attributetext">1.0</span>"<br><span class="attribute">exclude-result-prefixes</span>="<span class="attributetext">#default t ttp tts ttm msxsl cjb</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">output</span> <span class="attribute">encoding</span>="<span class="attributetext">utf-8</span>" <span class="attribute">indent</span>="<span class="attributetext">yes</span>" <span class="attribute">method</span>="<span class="attributetext">xml</span>" <span class="attribute">omit-xml-declaration</span>="<span class="attributetext">yes</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">msxsl</span>:<span class="element">script</span> <span class="attribute">language</span>="<span class="attributetext">C#</span>" <span class="attribute">implements-prefix</span>="<span class="attributetext">cjb</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string getMilliseconds(string time)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (string.IsNullOrEmpty(time) ? "" : TimeSpan.Parse(time).TotalMilliseconds.ToString());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string hyphenate(string str){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text.StringBuilder sb = new Text.StringBuilder("", 100);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (char c in str){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (char.IsUpper(c)){sb.Append("-");sb.Append(char.ToLower(c));}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else{sb.Append(c);}}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return sb.ToString();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">msxsl</span>:<span class="element">script</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">default-style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">for-each</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:styling/t:style[last()]</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">sort</span> <span class="attribute">order</span>="<span class="attributetext">ascending</span>" <span class="attribute">select</span>="<span class="attributetext">count(@tts:*)</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@id</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">for-each</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">variable</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">default-class</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/@xml:lang</span>" /&gt;<span class="text">cc<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">variable</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:tt</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">SAMI</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">HEAD</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">TITLE</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:metadata/ttm:title</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">TITLE</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">comment</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Copyright </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:metadata/ttm:copyright</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">comment</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/comment()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">STYLE</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">comment</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">$default-class</span>" /&gt;<span class="text"> {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text-align: center;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-family: arial, sans-serif;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-weight: normal;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; color: white;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-size: 16pt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name: </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/@xml:lang</span>" /&gt;<span class="text"> Subtitles;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lang: </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/@xml:lang</span>" /&gt;<span class="text">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SAMI_Type: CC;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* anything below will override above */<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:styling/t:style[@id=$default-style]/@tts:*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">comment</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">STYLE</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">HEAD</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:body</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">SAMI</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:body</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">BODY</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">BODY</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:body/t:div</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:p</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">start</span>" <span class="attribute">select</span>="<span class="attributetext">cjb:getMilliseconds(string(@begin))</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">end</span>" <span class="attribute">select</span>="<span class="attributetext">cjb:getMilliseconds(string(@end))</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">following-start</span>" <span class="attribute">select</span>="<span class="attributetext">cjb:getMilliseconds(string(following-sibling::t:p/@begin))</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Sync</span> <span class="attribute">START</span>="<span class="attributetext">{$start}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">p</span> <span class="attribute">class</span>="<span class="attributetext">{$default-class}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">@style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">class</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">$default-class</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">div</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">@style=$default-style and @tts:*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@tts:*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">@style!=$default-style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:head/t:styling/t:style[@id=current()/@style]/@tts:*|@tts:*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">div</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">p</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Sync</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">$end &amp;lt; ($following-start - 10)</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">Sync</span> <span class="attribute">START</span>="<span class="attributetext">{$end}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">p</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="element">nonbreakingspace</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">p</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="element">Sync</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">@tts:*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">cjb:hyphenate(local-name())</span>" /&gt;<span class="text">:</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">.</span>" /&gt;<span class="text">;<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">element</span> <span class="attribute">name</span>="<span class="attributetext">{local-name(.)}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">@tts:*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">style</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@tts:*</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*[namespace-uri()!='http://www.w3.org/2006/10/ttaf1#style']</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">element</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">text()</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span> /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">@*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">{local-name()}</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">.</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div><span class="string">'@</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">PROCESS</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$_</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$_</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$result</span><span class="operator">.</span><span class="foreground">replace</span><span class="foreground">(</span><span class="string">" xmlns=`"http://www.w3.org/2006/10/ttaf1`""</span><span class="operator">,</span>&nbsp;<span class="string">""</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$result</span><span class="operator">.</span><span class="foreground">replace</span><span class="foreground">(</span><span class="string">"&lt;nonbreakingspace /&gt;"</span><span class="operator">,</span>&nbsp;<span class="string">"&amp;nbsp;"</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">END</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$inxml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$result</span><span class="operator">.</span><span class="foreground">replace</span><span class="foreground">(</span><span class="string">" xmlns=`"http://www.w3.org/2006/10/ttaf1`""</span><span class="operator">,</span>&nbsp;<span class="string">""</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$result</span><span class="operator">.</span><span class="foreground">replace</span><span class="foreground">(</span><span class="string">"&lt;nonbreakingspace /&gt;"</span><span class="operator">,</span>&nbsp;<span class="string">"&amp;nbsp;"</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$result</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><span class="foreground">}</span><br></div></div> <p>The replaces on the $result string look like a bit of a hack but they do need to be there.</p> <p>It can be used like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:e4b1806c-6539-497b-a494-8a5fad870a78" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\T-TtafToSmiM1.ps1 # dot source this file<br>PS&gt; T-TtafToSmi [xml](gc ttaf.xml) | sc -encoding ascii<br></div></div> <p>or</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:55bbc8ef-208c-4d64-a553-6515e4dcabf0" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\T-TtafToSmiM1.ps1 # dot source this file<br>PS&gt; [xml](gc .\ttaf.xml) | T-TtafToSmi | sc -encoding ascii<br></div></div> <p>Here is the code</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fT-TtafToSmiM1.zip">T-TtafToSmiM1.zip (2.39 kb)</a></p>
http://www.bayes.co.uk/blog/post/Powershell-Translets-TTAF-to-SMI-M1.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=74e18d9d-faf2-4afb-846c-36c2dc209683 Sat, 7 Nov 2009 19:19:37 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=74e18d9d-faf2-4afb-846c-36c2dc209683 1 http://www.bayes.co.uk/blog/trackback.axd?id=74e18d9d-faf2-4afb-846c-36c2dc209683 http://www.bayes.co.uk/blog/post/Powershell-Translets-TTAF-to-SMI-M1.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=74e18d9d-faf2-4afb-846c-36c2dc209683

Powershell Translets TTAF to Srt

<p>Here is a translet that will transform Timed Text (TT) Authoring Format 1.0&nbsp; to SRT.</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:c713b5d5-0c1e-4faf-a41d-d223dbe3be3a" class="wlWriterSmartContent"> <div class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">T-TtafToSrt</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">BEGIN</span>&nbsp;<span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\invoke-transform.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">New-Object</span>&nbsp;<span class="commandarg">Xml.Xmldocument</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$xslt</span><span class="operator">.</span><span class="foreground">PSBase</span><span class="operator">.</span><span class="foreground">PreserveWhitespace</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$true</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$xslt</span><span class="operator">.</span><span class="foreground">LoadXml</span><span class="foreground">(</span><span class="string">@'</span><br> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"><br>xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>"<span class="attribute"><br>xmlns:t</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1</span>"<span class="attribute"><br>xmlns</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1</span>"<span class="attribute"><br>xmlns:ttp</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1#parameter</span>"<span class="attribute"><br>xmlns:tts</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1#style</span>"<span class="attribute"><br>xmlns:ttm</span>="<span class="attributetext">http://www.w3.org/2006/10/ttaf1#metadata</span>"<br><span class="attribute">version</span>="<span class="attributetext">1.0</span>"&gt;<span class="text"><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">output</span> <span class="attribute">indent</span>="<span class="attributetext">yes</span>" <span class="attribute">method</span>="<span class="attributetext">text</span>" /&gt;<span class="text"><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">/t:tt</span>"&gt;&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">/t:tt/t:body</span>" /&gt;&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:div</span>"&gt;&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">t:p</span>" /&gt;&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:p</span>"&gt;&lt;<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">count(preceding-sibling::t:p)</span>" /&gt;&lt;<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">concat(substring-before(@begin, '.'), ',', substring-after(@begin, '.'))</span>" /&gt;<span class="text">0 --&amp;gt; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">concat(substring-before(@begin, '.'), ',', substring-after(@begin, '.'))</span>" /&gt;<span class="text">0<br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> /&gt;&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">t:br</span>"&gt;&lt;<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">node()|@*</span>"&gt;<span class="text"><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br></span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div><span class="string">'@</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">PROCESS</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$_</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$_</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">END</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$xml</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$xml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><span class="foreground">}</span><br></div></div> <p>It can be used like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:51fe71d8-135a-413a-84dd-7ac895d2d7f9" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\T-TtafToSrt.ps1 # dot source this file<br>PS&gt; T-TtafToSrt [xml(gc .\ttaf.xml) | sc -encoding ascii<br></div></div> <p>or</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:95eb5b2e-ffd0-4a72-adf2-ad440c1b0c7f" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; . .\T-TtafToSrt.ps1 # dot source this file<br>PS&gt; [xml](gc .\ttaf.xml) | T-TtafToSrt | sc -encoding ascii<br></div></div> <p>Note that if you aren't passing it on down the pipeline and are sending it to a file you have to set the encoding to ascii or applications will ignore it.</p> <p>Here is the code.</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fT-TtafToSrt.zip">T-TtafToSrt.zip (1.10 kb)</a></p>
http://www.bayes.co.uk/blog/post/Powershell-Translets-TTAF-to-Srt.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=d55537fe-a0e5-49c6-8ff0-0847ba6166f4 Fri, 6 Nov 2009 18:41:44 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=d55537fe-a0e5-49c6-8ff0-0847ba6166f4 12 http://www.bayes.co.uk/blog/trackback.axd?id=d55537fe-a0e5-49c6-8ff0-0847ba6166f4 http://www.bayes.co.uk/blog/post/Powershell-Translets-TTAF-to-Srt.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=d55537fe-a0e5-49c6-8ff0-0847ba6166f4

Powershell Translets Powershell as Xslt Scripting Language

<p>One would think this should be easy. Just put Powershell into the Language of an msxsl:script element. But it doesn't work :-D</p> <p align="center"><a href="http://www.bayes.co.uk/blog/image.axd?picture=ScriptingLanguageNotSupported.jpg"><img alt="ScriptingLanguageNotSupported" src="http://www.bayes.co.uk/blog/image.axd?picture=ScriptingLanguageNotSupported_thumb.jpg" width="440" height="64"></a> </p> <p>Pity.&nbsp; I rooted around and the language attribute can be any of the CodeDomProviders available on the system.</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:eb871881-05dc-467b-a895-dd73aeb3b34f" class="wlWriterSmartContent"> <div class="powershellbackground">PS&gt; [System.CodeDom.Compiler.CodeDomProvider]::GetAllCompilerInfo()<br><br>CodeDomProviderType IsCodeDomProviderTypeValid<br>------------------- --------------------------<br>Microsoft.CSharp.CSharpCodeProvider True<br>Microsoft.VisualBasic.VBCodeProvider True<br>Microsoft.JScript.JScriptCodeProvider True<br>Microsoft.VisualC.CppCodeProvider True<br></div></div> <p>According to <a href="http://www.vistax64.com/powershell/252293-codedom-provider-powershell.html">this</a>there won't be one for Powershell soon. Never mind, I still want to use Powershell from Xslt. So I tried this.</p> <p></p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:10036041-7e33-486e-9f05-9e3da039960d" class="wlWriterSmartContent"> <div style="overflow-y: auto; height: 300px" class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">T-AddChecksum</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">begin</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\invoke-transform.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br><span class="string">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span><br><span class="string">&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"</span><br><span class="string"> xmlns:msxsl="urn:schemas-microsoft-com:xslt"</span><br><span class="string"> xmlns:cjb="cjb"</span><br><span class="string">&gt;</span><br><span class="string"></span><br><span class="string">&nbsp; &lt;xsl:template match="node()|@*"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:copy&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:apply-templates select="@*|node()"/&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;/xsl:copy&gt;</span><br><span class="string">&nbsp; &lt;/xsl:template&gt;</span><br><span class="string">&nbsp; &lt;xsl:template match="*[local-name()='file']"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:variable name="fname"&gt;&lt;xsl:call-template name="get-path" /&gt;&lt;/xsl:variable&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:copy&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:apply-templates select="@*|node()"/&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:attribute name="Checksum"&gt;&lt;xsl:value-of select="cjb:GetChecksum(string($fname))" /&gt;&lt;/xsl:attribute&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;/xsl:copy&gt;</span><br><span class="string">&nbsp; &lt;/xsl:template&gt;</span><br><span class="string">&nbsp; &lt;xsl:template name="get-path"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:for-each select="ancestor-or-self::*[not(@Root)]"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="@Base" /&gt;&lt;xsl:text&gt;\&lt;/xsl:text&gt;&lt;xsl:value-of select="@Name" /&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;/xsl:for-each&gt;</span><br><span class="string">&nbsp; &lt;/xsl:template&gt;</span><br><span class="string">&lt;/xsl:stylesheet&gt;</span><br><span class="string">'@</span><br><br><span class="variable">$func</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br><span class="string">&nbsp;&nbsp;&nbsp; function GetChecksum([string]$file){</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $stream = [System.IO.File]::OpenRead($file)</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sha256 = new-object System.Security.Cryptography.SHA256Managed</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $checksum = $sha256.ComputeHash($stream)</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [System.BitConverter]::ToString($checksum).Replace("-", [system.String]::Empty)</span><br><span class="string">&nbsp;&nbsp;&nbsp; }</span><br><span class="string">'@</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$pso</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">psobject</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$pso</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">add-member</span>&nbsp;<span class="commandparam">-inputobject</span>&nbsp;<span class="variable">$pso</span>&nbsp;<span class="commandparam">-membertype</span>&nbsp;<span class="commandarg">scriptmethod</span>&nbsp;<span class="commandparam">-name</span>&nbsp;<span class="commandarg">GetChecksum</span>&nbsp;<span class="commandparam">-value</span>&nbsp;<span class="foreground">{</span><span class="variable">$func</span><span class="foreground">}</span>&nbsp;<span class="commandparam">-PassThru</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">process</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$_</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$_</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-extensionobjects</span>&nbsp;<span class="foreground">@{</span><span class="string">"cjb"</span><span class="operator">=</span><span class="variable">$pso</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">end</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$inxml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-extensionobjects</span>&nbsp;<span class="foreground">@{</span><span class="string">"cjb"</span><span class="operator">=</span><span class="variable">$pso</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><span class="foreground">}</span><br></div></div> <p></p> <p>But that doesn't work. It is so long since I wrote it I can't remember if it worked, worked under version 1.0, worked in the CTP, seemed like a good idea that should work but didn't or it didn't work at all. Anyway it still looks like a good idea to me.</p> <p>This is the object created with C# in the previous example.</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:6cf3f6f6-8616-4762-95f9-5f3225196a6c" class="wlWriterSmartContent"> <div class="powershellbackground">PS &gt; $cs|gm<br>TypeName: Checksum<br>Name MemberType Definition <br>---- ---------- ---------- <br>Equals Method bool Equals(System.Object obj) <br>GetChecksum Method string GetChecksum(string file)<br>GetHashCode Method int GetHashCode() <br>GetType Method type GetType() <br>ToString Method string ToString() <br></div></div> <p>This is the Powershell object created with PSObject</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:eeb2842b-8914-48a8-b16c-f54d2db37602" class="wlWriterSmartContent"> <div class="powershellbackground">PS D:\powershell\temp&gt; $pso|gm<br>TypeName: System.Management.Automation.PSCustomObject<br>Name MemberType Definition <br>---- ---------- ---------- <br>Equals Method bool Equals(System.Object obj)<br>GetHashCode Method int GetHashCode() <br>GetType Method type GetType() <br>ToString Method string ToString() <br>GetChecksum ScriptMethod System.Object GetChecksum(); <br></div></div> <p>So it is not a valid Xslt extension object?</p> <p>Right, so we can call C# from Xslt via an extension object and we can call Powershell from C# so all we have to do is write a C# wrapper around the Powershell script and we can call Powershell from Xslt.</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:a68416bb-76f9-49f6-8982-98b15f7b8e91" class="wlWriterSmartContent"> <div class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">T-AddChecksum</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">begin</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\invoke-transform.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br><span class="string">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span><br><span class="string">&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"</span><br><span class="string"> xmlns:msxsl="urn:schemas-microsoft-com:xslt"</span><br><span class="string"> xmlns:cjb="cjb"</span><br><span class="string">&gt;</span><br><span class="string">&nbsp; &lt;xsl:template match="node()|@*"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:copy&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:apply-templates select="@*|node()"/&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;/xsl:copy&gt;</span><br><span class="string">&nbsp; &lt;/xsl:template&gt;</span><br><span class="string">&nbsp; &lt;xsl:template match="*[local-name()='file']"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:variable name="fname"&gt;&lt;xsl:call-template name="get-path" /&gt;&lt;/xsl:variable&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:copy&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:apply-templates select="@*|node()"/&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:attribute name="Checksum"&gt;&lt;xsl:value-of select="cjb:GetChecksum(string($fname))" /&gt;&lt;/xsl:attribute&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;/xsl:copy&gt;</span><br><span class="string">&nbsp; &lt;/xsl:template&gt;</span><br><span class="string">&nbsp; &lt;xsl:template name="get-path"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:for-each select="ancestor-or-self::*[not(@Root)]"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="@Parent" /&gt;&lt;xsl:text&gt;\&lt;/xsl:text&gt;&lt;xsl:value-of select="@Name" /&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;/xsl:for-each&gt;</span><br><span class="string">&nbsp; &lt;/xsl:template&gt;</span><br><span class="string">&lt;/xsl:stylesheet&gt;</span><br><span class="string">'@</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$code</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br><span class="string">using System;</span><br><span class="string">using System.Management.Automation;</span><br><span class="string"></span><br><span class="string">public partial class PSCaller</span><br><span class="string">{</span><br><span class="string">&nbsp;&nbsp;&nbsp; ScriptBlock _script;</span><br><span class="string"></span><br><span class="string">&nbsp;&nbsp;&nbsp; public PSCaller(ScriptBlock script) { Script = script; }</span><br><span class="string">&nbsp;&nbsp;&nbsp; public ScriptBlock Script</span><br><span class="string">&nbsp;&nbsp;&nbsp; {</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { return _script; }</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set { _script = value; }</span><br><span class="string">&nbsp;&nbsp;&nbsp; }</span><br><span class="string">&nbsp;&nbsp;&nbsp; public String GetChecksum(String file)</span><br><span class="string">&nbsp;&nbsp;&nbsp; {</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (string)Script.Invoke(file)[0].BaseObject;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch(Exception ex) {</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new InvalidOperationException("Script failed***!", ex);</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span><br><span class="string">&nbsp;&nbsp;&nbsp; }</span><br><span class="string">}</span><br><span class="string">'@</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">Add-Type</span>&nbsp;<span class="commandparam">-TypeDefinition</span>&nbsp;<span class="variable">$code</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$psco</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">PSCaller</span><span class="foreground">(</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$file</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$args</span><span class="operator">[</span><span class="number">0</span><span class="operator">]</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$stream</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[System.IO.File]</span><span class="operator">::</span><span class="foreground">OpenRead</span><span class="foreground">(</span><span class="variable">$file</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$sha256</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Security.Cryptography.SHA256Managed</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$checksum</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$sha256</span><span class="operator">.</span><span class="foreground">ComputeHash</span><span class="foreground">(</span><span class="variable">$stream</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[System.BitConverter]</span><span class="operator">::</span><span class="foreground">ToString</span><span class="foreground">(</span><span class="variable">$checksum</span><span class="foreground">)</span><span class="operator">.</span><span class="foreground">Replace</span><span class="foreground">(</span><span class="string">"-"</span><span class="operator">,</span>&nbsp;<span class="type">[system.String]</span><span class="operator">::</span><span class="foreground">Empty</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">process</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$_</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-extensionobjects</span>&nbsp;<span class="foreground">@{</span><span class="string">"cjb"</span><span class="operator">=</span><span class="variable">$psco</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">end</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$inxml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-extensionobjects</span>&nbsp;<span class="foreground">@{</span><span class="string">"cjb"</span><span class="operator">=</span><span class="variable">$psco</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><span class="foreground">}</span><br></div></div> <p>This works but it is a bit clunky. The name and signature 'String GetChecksum(String file)' is in the C# script and is seperate from the actual code that is in the Powershell script. A right mashup :-)</p> <p>What we need is a way of describing the signature and Powershell script in one place. I started looking at DSLs. Here is a simple class/method DSL</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:4c8f4db6-91c1-4b43-895a-2ba60fc854bc" class="wlWriterSmartContent"> <div class="highlightbackground"><span class="variable">$dsl</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="command">psclass</span>&nbsp;<span class="commandarg">public</span>&nbsp;<span class="commandarg">PSCaller</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">method</span>&nbsp;<span class="commandarg">String</span>&nbsp;<span class="commandarg">GetChecksum</span><span class="foreground">(</span><span class="operator"></span><span class="type">[String]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$file</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$args</span><span class="operator">[</span><span class="number">0</span><span class="operator">]</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$stream</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[System.IO.File]</span><span class="operator">::</span><span class="foreground">OpenRead</span><span class="foreground">(</span><span class="variable">$file</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$sha256</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Security.Cryptography.SHA256Managed</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$checksum</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$sha256</span><span class="operator">.</span><span class="foreground">ComputeHash</span><span class="foreground">(</span><span class="variable">$stream</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[System.BitConverter]</span><span class="operator">::</span><span class="foreground">ToString</span><span class="foreground">(</span><span class="variable">$checksum</span><span class="foreground">)</span><span class="operator">.</span><span class="foreground">Replace</span><span class="foreground">(</span><span class="string">"-"</span><span class="operator">,</span>&nbsp;<span class="type">[system.String]</span><span class="operator">::</span><span class="foreground">Empty</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><span class="foreground">}</span><br></div></div> <p>I was using 'class' as the class keyword but it is now a Powershell reserved word so I am using 'psclass'. It can handle multiple methods with multiple arguments and the arguments can be any type i.e. [System.Xml.XmlElement]. This example code defines 1 method with the signature 'String GetChecksum([String])' followed by the script itself. It produces the following C#</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:60e3b905-923a-4495-b4ba-2efb424f7800" class="wlWriterSmartContent"><!-- --> <div class="highlightbackground"><pre class="csharpcode"><span class="kwrd">using</span> System; <span class="kwrd">using</span> System.Collections; <span class="kwrd">using</span> System.Management.Automation; <span class="kwrd">using</span> System.Xml; <span class="kwrd">public</span> <span class="kwrd">class</span> PSCaller { ScriptBlock script0; <span class="kwrd">public</span> PSCaller(ScriptBlock Script0) { script0 = Script0; } <span class="kwrd">public</span> String GetChecksum(<span class="kwrd">string</span> p0) { ScriptBlock Script = script0; <span class="kwrd">try</span> { <span class="kwrd">return</span> (String)Script.Invoke(p0)[0].BaseObject; } <span class="kwrd">catch</span> (Exception ex) { <span class="kwrd">throw</span> <span class="kwrd">new</span> InvalidOperationException(<span class="str">"Script failed***!"</span>, ex); } } }</pre></div></div> <p>and an array of ScriptBlocks. It then compiles the code and passes the array of ScriptBlocks to the new object constructor.</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:c8a817e8-2f4b-4e39-8a62-452900531e9b" class="wlWriterSmartContent"> <div class="highlightbackground"><span class="type">[string]</span><span class="variable">$code</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="operator">&amp;</span><span class="variable">$dsl</span><br><span class="command">Add-Type</span>&nbsp;<span class="commandparam">-TypeDefinition</span>&nbsp;<span class="variable">$code</span>&nbsp;<span class="commandparam">-ReferencedAssemblies</span>&nbsp;<span class="commandarg">System.xml</span><br><span class="variable">$NewObject</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="variable">PSCaller</span><span class="foreground">(</span><span class="variable">$scriptArray</span><span class="foreground">)</span><br><br></div></div> <p>This is what the object looks like.</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:da6df8de-1c30-4bf0-b71b-bc8265d3f55d" class="wlWriterSmartContent"> <div class="powershellbackground">PS &gt; $newobject|gm<br>TypeName: PSCaller2<br>Name MemberType Definition <br>---- ---------- ---------- <br>Equals Method bool Equals(System.Object obj) <br>GetChecksum Method string GetChecksum(string p0) <br>GetDifferentChecksum Method string GetDifferentChecksum(string p0)<br>GetHashCode Method int GetHashCode() <br>GetType Method type GetType() <br>ToString Method string ToString() <br></div></div> <p>So this is what a Translet might look like</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:18102b78-09fd-4840-8361-9f25e1012573" class="wlWriterSmartContent"> <div class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">T-AddChecksum</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">begin</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\invoke-transform.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\Create-ObjectFromDSL.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br><span class="string">&lt;?xml version="1.0" encoding="utf-8"?&gt;</span><br><span class="string">&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"</span><br><span class="string"> xmlns:msxsl="urn:schemas-microsoft-com:xslt"</span><br><span class="string"> xmlns:cjb="cjb"</span><br><span class="string">&gt;</span><br><span class="string">&nbsp; &lt;xsl:template match="node()|@*"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:copy&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:apply-templates select="@*|node()"/&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;/xsl:copy&gt;</span><br><span class="string">&nbsp; &lt;/xsl:template&gt;</span><br><span class="string">&nbsp; &lt;xsl:template match="*[local-name()='file']"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:variable name="fname"&gt;&lt;xsl:call-template name="get-path" /&gt;&lt;/xsl:variable&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:copy&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:apply-templates select="@*|node()"/&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:attribute name="Checksum"&gt;&lt;xsl:value-of select="cjb:GetChecksum(string($fname))" /&gt;&lt;/xsl:attribute&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;/xsl:copy&gt;</span><br><span class="string">&nbsp; &lt;/xsl:template&gt;</span><br><span class="string">&nbsp; &lt;xsl:template name="get-path"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;xsl:for-each select="ancestor-or-self::*[not(@Root)]"&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;xsl:value-of select="@Parent" /&gt;&lt;xsl:text&gt;\&lt;/xsl:text&gt;&lt;xsl:value-of select="@Name" /&gt;</span><br><span class="string">&nbsp;&nbsp;&nbsp; &lt;/xsl:for-each&gt;</span><br><span class="string">&nbsp; &lt;/xsl:template&gt;</span><br><span class="string">&lt;/xsl:stylesheet&gt;</span><br><span class="string">'@</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$dsl</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">psclass</span>&nbsp;<span class="commandarg">public</span>&nbsp;<span class="commandarg">PSCaller</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">method</span>&nbsp;<span class="commandarg">String</span>&nbsp;<span class="commandarg">GetChecksum</span><span class="foreground">(</span><span class="type">[String]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$file</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$args</span><span class="operator">[</span><span class="number">0</span><span class="operator">]</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$stream</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[System.IO.File]</span><span class="operator">::</span><span class="foreground">OpenRead</span><span class="foreground">(</span><span class="variable">$file</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$sha256</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Security.Cryptography.SHA256Managed</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$checksum</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$sha256</span><span class="operator">.</span><span class="foreground">ComputeHash</span><span class="foreground">(</span><span class="variable">$stream</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[System.BitConverter]</span><span class="operator">::</span><span class="foreground">ToString</span><span class="foreground">(</span><span class="variable">$checksum</span><span class="foreground">)</span><span class="operator">.</span><span class="foreground">Replace</span><span class="foreground">(</span><span class="string">"-"</span><span class="operator">,</span>&nbsp;<span class="type">[system.String]</span><span class="operator">::</span><span class="foreground">Empty</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">method</span>&nbsp;<span class="commandarg">String</span>&nbsp;<span class="commandarg">GetDifferentChecksum</span><span class="foreground">(</span><span class="type">[String]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$file</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$args</span><span class="operator">[</span><span class="number">0</span><span class="operator">]</span>&nbsp;<span class="comment">#different</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$stream</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="type">[System.IO.File]</span><span class="operator">::</span><span class="foreground">OpenRead</span><span class="foreground">(</span><span class="variable">$file</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$sha256</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">new-object</span>&nbsp;<span class="commandarg">System.Security.Cryptography.SHA256Managed</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$checksum</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$sha256</span><span class="operator">.</span><span class="foreground">ComputeHash</span><span class="foreground">(</span><span class="variable">$stream</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[System.BitConverter]</span><span class="operator">::</span><span class="foreground">ToString</span><span class="foreground">(</span><span class="variable">$checksum</span><span class="foreground">)</span><span class="operator">.</span><span class="foreground">Replace</span><span class="foreground">(</span><span class="string">"-"</span><span class="operator">,</span>&nbsp;<span class="type">[system.String]</span><span class="operator">::</span><span class="foreground">Empty</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$psco</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">Create-ObjectFromDSL</span>&nbsp;<span class="variable">$dsl</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">process</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$_</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$_</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-extensionobjects</span>&nbsp;<span class="foreground">@{</span><span class="string">"cjb"</span><span class="operator">=</span><span class="variable">$psco</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">end</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$inxml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-extensionobjects</span>&nbsp;<span class="foreground">@{</span><span class="string">"cjb"</span><span class="operator">=</span><span class="variable">$psco</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><span class="foreground">}</span><br></div></div> <p>To use it you need the Create-ObjectFromDSL.ps1 script. Here it is</p> <p><a href="http://www.bayes.co.uk/blog/file.axd?file=2009%2f11%2fCreate-ObjectFromDSL.zip">Create-ObjectFromDSL.zip (953.00 bytes)</a></p> <p>Why you would want to do this and what you would use it for is up to you. Most people would use Java, JavaScript or C# to extend Xslt. In most cases I would generate Xml from the things that Powershell can do well and pass that into a transform. But this just shows that is is partly possible to use Powershell as an Xslt scripting language and it adds another arrow to your quiver.</p> <p>Since we have to do the Create-ObjectFromDSL step anyway we could change the Xslt to something like this</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:5f6e3123-c76e-4b29-81e8-9ad58a1c39b5" class="wlWriterSmartContent"> <div class="highlightbackground"> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"> xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>"<span class="attribute"><br>xmlns:cjbxsl</span>="<span class="attributetext">urn:schemas-bayes-co-uk:xslt</span>"<span class="attribute"><br>xmlns:ucjb</span>="<span class="attributetext">urn:schemas-bayes-co-uk:extension-object</span>" <span class="attribute">version</span>="<span class="attributetext">1.0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">cjbxsl</span>:<span class="element">script</span> <span class="attribute">language</span>="<span class="attributetext">Powershell</span>" <span class="attribute">implements-prefix</span>="<span class="attributetext">ucjb</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">cjbxsl</span>:<span class="element">method</span> <span class="attribute">name</span>="<span class="attributetext">GetChecksum</span>" <span class="attribute">returns</span>="<span class="attributetext">string</span>" <span class="attribute">args</span>="<span class="attributetext">string</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;![CDATA[<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $file = $args[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $stream = [System.IO.File]::OpenRead($file)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sha256 = new-object System.Security.Cryptography.SHA256Managed<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $checksum = $sha256.ComputeHash($stream)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [System.BitConverter]::ToString($checksum).Replace("-", [system.String]::Empty)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]]&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">cjbxsl</span>:<span class="element">method</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">cjbxsl</span>:<span class="element">script</span>&gt;<span class="text"><br><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">node()|@*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">*[local-name()='file']</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">fname</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">call-template</span> <span class="attribute">name</span>="<span class="attributetext">get-path</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">variable</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">Checksum</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">ucjb:GetChecksum(string($fname))</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">name</span>="<span class="attributetext">get-path</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">for-each</span> <span class="attribute">select</span>="<span class="attributetext">ancestor-or-self::*[not(@Root)]</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@Parent</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text">\</span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@Name</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">for-each</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div></div></div> <p>then we can pass the stylesheet through another translet to create the C# and the extension object :-D. The output from that translet would be the extension object that is actually passed as the extension object to the original stylesheet and used in the pipeline. Oh dizzy!</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:19ff5098-c3e6-4a71-9e40-ae9fa146efd1" class="wlWriterSmartContent"> <div class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">T-CreateObjectFromPSScriptXslt</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">begin</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\invoke-transform.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">New-Object</span>&nbsp;<span class="commandarg">Xml.Xmldocument</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$xslt</span><span class="operator">.</span><span class="foreground">PSBase</span><span class="operator">.</span><span class="foreground">PreserveWhitespace</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="variable">$true</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$xslt</span><span class="operator">.</span><span class="foreground">LoadXml</span><span class="foreground">(</span><span class="string">@'</span><br> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"> xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>"<span class="attribute"><br>xmlns:cjbxsl</span>="<span class="attributetext">urn:schemas-bayes-co-uk:xslt</span>" <span class="attribute">version</span>="<span class="attributetext">1.0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">output</span> <span class="attribute">method</span>="<span class="attributetext">text</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">cjbxsl:script</span>"&gt;<span class="text"><br>$code=@"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using System;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using System.Collections;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using System.Management.Automation;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using System.Xml;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public class </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@assembly-name</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">declarations</span>" /&gt;<span class="text"><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@assembly-name</span>" /&gt;<span class="text">(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">constructor-args</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">constructor-body</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">methods</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>"@<br>Add-Type -TypeDefinition $code -ReferencedAssemblies System.xml<br>$NewObject = New-Object </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@assembly-name</span>" /&gt;<span class="text">(</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">new-object</span>" /&gt;<span class="text">)<br>$NewObject<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">declarations</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public ScriptBlock script</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">count(preceding::cjbxsl:method)</span>" /&gt;<span class="text">;<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">constructor-args</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScriptBlock Script</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">count(preceding::cjbxsl:method)</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">not(position()=last())</span>"&gt;<span class="text">, </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">constructor-body</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; script</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">count(preceding::cjbxsl:method)</span>" /&gt;<span class="text"> = Script</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">count(preceding::cjbxsl:method)</span>" /&gt;<span class="text">;<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">methods</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@returns</span>" /&gt;<span class="text">&nbsp;</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text">&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text">&nbsp;</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@name</span>" /&gt;<span class="text">(</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@args</span>" /&gt;<span class="text">)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ScriptBlock Script = script</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">count(preceding::cjbxsl:method)</span>" /&gt;<span class="text">;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (String)Script.Invoke(p0)[0].BaseObject;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (Exception ex)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new InvalidOperationException("Script failed***!", ex);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">cjbxsl:method</span>" <span class="attribute">mode</span>="<span class="attributetext">new-object</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">.</span>" /&gt;<span class="text">}</span>&lt;<span class="nsprefix">xsl</span>:<span class="element">if</span> <span class="attribute">test</span>="<span class="attributetext">not(position()=last())</span>"&gt;<span class="text">,</span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">if</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">@* | node()</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@* | node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div><span class="string">'@</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">process</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$_</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$_</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">end</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$inxml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><span class="foreground">}</span><br></div></div> <p>And here is a stylesheet that will use it</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:887EC618-8FBE-49a5-A908-2339AF2EC720:de52f16c-269c-460a-8ac1-a3209ea34827" class="wlWriterSmartContent"> <div class="highlightbackground"><span class="keyword">function</span>&nbsp;<span class="commandarg">T-AddChecksum</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">param</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">begin</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\xslt\T-CreateObjectFromPSScriptXslt.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="operator">.</span>&nbsp;<span class="command">pslib:\xml\invoke-transform.ps1</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="variable">$xslt</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="string">@'</span><br> <div class="xml">&lt;<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span><span class="attribute"> xmlns:xsl</span>="<span class="attributetext">http://www.w3.org/1999/XSL/Transform</span>"<span class="attribute"> xmlns:cjbxsl</span>="<span class="attributetext">urn:schemas-bayes-co-uk:xslt</span>"<span class="attribute"> xmlns:ucjb</span>="<span class="attributetext">urn:cjb</span>" <span class="attribute">version</span>="<span class="attributetext">1.0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">cjbxsl</span>:<span class="element">script</span> <span class="attribute">language</span>="<span class="attributetext">Powershell</span>" <span class="attribute">implements-prefix</span>="<span class="attributetext">ucjb</span>" <span class="attribute">assembly-name</span>="<span class="attributetext">ChecksumSHA3</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">cjbxsl</span>:<span class="element">method</span> <span class="attribute">name</span>="<span class="attributetext">GetChecksum</span>" <span class="attribute">returns</span>="<span class="attributetext">string</span>" <span class="attribute">args</span>="<span class="attributetext">string p0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;![CDATA[<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $file = $args[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $stream = [System.IO.File]::OpenRead($file)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sha256 = new-object System.Security.Cryptography.SHA256Managed<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $checksum = $sha256.ComputeHash($stream)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [System.BitConverter]::ToString($checksum).Replace("-", [system.String]::Empty)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]]&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">cjbxsl</span>:<span class="element">method</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">cjbxsl</span>:<span class="element">method</span> <span class="attribute">name</span>="<span class="attributetext">GetChecksum384</span>" <span class="attribute">returns</span>="<span class="attributetext">string</span>" <span class="attribute">args</span>="<span class="attributetext">string p0</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;![CDATA[<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $file = $args[0]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $stream = [System.IO.File]::OpenRead($file)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $sha384 = new-object System.Security.Cryptography.SHA384Managed<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $checksum = $sha384.ComputeHash($stream)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [System.BitConverter]::ToString($checksum).Replace("-", [system.String]::Empty)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]]&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">cjbxsl</span>:<span class="element">method</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">cjbxsl</span>:<span class="element">script</span>&gt;<span class="text"><br><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">node()|@*</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">match</span>="<span class="attributetext">*[local-name()='file']</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">variable</span> <span class="attribute">name</span>="<span class="attributetext">fname</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">call-template</span> <span class="attribute">name</span>="<span class="attributetext">get-path</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">variable</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">apply-templates</span> <span class="attribute">select</span>="<span class="attributetext">@*|node()</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">attribute</span> <span class="attribute">name</span>="<span class="attributetext">Checksum</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">ucjb:GetChecksum(string($fname))</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">attribute</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">copy</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">template</span> <span class="attribute">name</span>="<span class="attributetext">get-path</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">for-each</span> <span class="attribute">select</span>="<span class="attributetext">ancestor-or-self::*[not(@Root)]</span>"&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@Parent</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text">\</span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">text</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;<span class="nsprefix">xsl</span>:<span class="element">value-of</span> <span class="attribute">select</span>="<span class="attributetext">@Name</span>" /&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">for-each</span>&gt;<span class="text"><br>&nbsp;&nbsp;&nbsp; </span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">template</span>&gt;<span class="text"><br></span>&lt;/<span class="nsprefix">xsl</span>:<span class="element">stylesheet</span>&gt;<br></div><span class="string">'@</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="variable">$psco</span>&nbsp;<span class="operator">=</span>&nbsp;<span class="command">Invoke-Expression</span> (<span class="command">T-CreateObjectFromPSScriptXslt</span>&nbsp;<span class="variable">$xslt</span>)<br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">process</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$_</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$_</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-extensionObjects</span>&nbsp;<span class="foreground">@{</span><span class="foreground">ucjb</span><span class="operator">=</span><span class="variable">$psco</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="keyword">end</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="keyword">if</span>&nbsp;<span class="foreground">(</span><span class="variable">$inxml</span>&nbsp;<span class="operator">-is</span>&nbsp;<span class="type">[xml]</span><span class="foreground">)</span><span class="foreground">{</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="type">[xml]</span><span class="foreground">(</span><span class="command">invoke-transform</span>&nbsp;<span class="commandparam">-inxml</span>&nbsp;<span class="variable">$inxml</span>&nbsp;<span class="commandparam">-inxsl</span>&nbsp;<span class="variable">$xslt</span>&nbsp;<span class="commandparam">-extensionObjects</span>&nbsp;<span class="foreground">@{</span><span class="foreground">ucjb</span><span class="operator">=</span><span class="variable">$psco</span><span class="foreground">}</span><span class="foreground">)</span><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br>&nbsp;&nbsp;&nbsp; <span class="foreground">}</span><br><span class="foreground">}</span><br></div></div> <p>Voila!!! Powershell as an xslt scripting language. <img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="happyrabbit2" src="http://www.bayes.co.uk/blog/image.axd?picture=happyrabbit2_2.gif" width="36" height="46"></p>
http://www.bayes.co.uk/blog/post/Powershell-Translets-Powershell-as-Xslt-Scripting-Language.aspx#comment http://www.bayes.co.uk/blog/post.aspx?id=8cd2d2b4-1ed2-4ac5-9713-a506556a9363 Thu, 5 Nov 2009 15:19:35 +0000 chris http://www.bayes.co.uk/blog/pingback.axd http://www.bayes.co.uk/blog/post.aspx?id=8cd2d2b4-1ed2-4ac5-9713-a506556a9363 902 http://www.bayes.co.uk/blog/trackback.axd?id=8cd2d2b4-1ed2-4ac5-9713-a506556a9363 http://www.bayes.co.uk/blog/post/Powershell-Translets-Powershell-as-Xslt-Scripting-Language.aspx#comment http://www.bayes.co.uk/blog/syndication.axd?post=8cd2d2b4-1ed2-4ac5-9713-a506556a9363

 
 
  
     
Open

Delete

View XML
View XSL