<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Huddled Masses &#187; Xsl</title>
	<atom:link href="http://huddledmasses.org/tag/xsl/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Fri, 27 Apr 2012 05:42:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Ignoring Namespaces in XPath</title>
		<link>http://huddledmasses.org/ignoring-namespaces-in-xpath/</link>
		<comments>http://huddledmasses.org/ignoring-namespaces-in-xpath/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 21:32:51 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Xml]]></category>
		<category><![CDATA[XPath]]></category>
		<category><![CDATA[Xsl]]></category>
		<category><![CDATA[Xslt]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1348</guid>
		<description><![CDATA[I know that I just wrote a post last week about XPath and namespaces in PowerShell, but at the time I left out one possible way of dealing with namespaces, because it&#8217;s not the right way of doing things. However, sometimes it&#8217;s nice to have options, and when you&#8217;re working on the command-line in PowerShell, [...]]]></description>
			<content:encoded><![CDATA[	<p>I know that I just wrote a post last week about <a href="http://huddledmasses.org/xpath-and-namespaces-in-powershell/">XPath and namespaces in PowerShell</a>, but at the time I left out one possible way of dealing with namespaces, because it&#8217;s not the <em>right</em> way of doing things.  However, sometimes it&#8217;s nice to have options, and when you&#8217;re working on the command-line in PowerShell, or just trying to figure out a proof-of-concept call to a web service, you really don&#8217;t <em>need</em> to deal with namespaces correctly, you just need it to work.</p>

	<p>With that in mind, I present to you the fourth option: just strip the namespaces out!  The simplest way to do that is to run the <span class="caps">XML</span> through an <span class="caps">XSL</span> stylesheet which just outputs the <code>local-name()</code> of each node (including attributes), and remove any namespace definitions (processing instructions).</p>

	<div class="xml code xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:output</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;xml&quot;</span> <span style="color: #000066;">indent</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/|comment()|processing-instruction()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:apply-templates<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;{local-name()}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:apply-templates<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;@*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;{local-name()}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:value-of<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/xsl:output<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div>

	<p>That stylesheet and the basic steps of the process will work anywhere, from Java to C# to the web &#8230; but since my current language of choice for prototyping is PowerShell, I&#8217;ll show you how to implement it there as <a href="http://poshcode.org/1492">Remove-XmlNamespace</a>. Once you have that, I think you&#8217;ll see that it was relatively simple for me to write <a href="http://poshcode.org/1504">a new Select-XML</a> which adds a parameter <code>RemoveNamespace</code> which is implemented by calling this <a href="http://poshcode.org/1492">Remove-XmlNamespace</a> &#8230;</p>

	<p>That actually allows you to call <code>Select-Xml</code> with the <code>-RemoveNamespace</code> parameter just as though the namespaces didn&#8217;t exist.  Of course, the returned <span class="caps">XML</span> nodes will, in fact, <span class="caps">NOT</span> have namespaces &#8230; so they may not be quite the same as the source, but the data will all be there.  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':-)' class='wp-smiley' /> </p>

<span id="more-1348"></span>

<script type="text/javascript" src="http://PoshCode.org/embed/1504"></script>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/bba0ce48-3de7-4675-8c1a-a449e3ae8a96/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=bba0ce48-3de7-4675-8c1a-a449e3ae8a96" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/ignoring-namespaces-in-xpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert-Xml with XSLT in PowerShell</title>
		<link>http://huddledmasses.org/convert-xml-with-xslt-in-powershell/</link>
		<comments>http://huddledmasses.org/convert-xml-with-xslt-in-powershell/#comments</comments>
		<pubDate>Wed, 19 Dec 2007 04:54:04 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Xml]]></category>
		<category><![CDATA[Xsl]]></category>
		<category><![CDATA[Xslt]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/convert-xml-with-xslt-in-powershell/</guid>
		<description><![CDATA[Just a quick post to upload a simple PowerShell script that transforms XML files with XSL files. There&#8217;s actually a cmdlet in PowerShell Community Extensions which does this, but believe it or not, in all my tests the script outperforms the cmdlet (the cmdlet takes, on average, 117ms on a file which takes the script [...]]]></description>
			<content:encoded><![CDATA[	<p>Just a quick post to upload a simple PowerShell script that transforms <span class="caps">XML</span> files with <span class="caps">XSL</span> files.  There&#8217;s actually a cmdlet in <a href="http://CodePlex.com/PowerShellCX/">PowerShell Community Extensions</a> which does this, but believe it or not, in all my tests the script outperforms the cmdlet (the cmdlet takes, on average, 117ms on a file which takes the script 63ms on average).</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Convert-<span style="font-style: normal;">WithXslt</span></span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$originalXmlFilePath</span>, <span style="color: #660033; font-weight: bold;">$xslFilePath</span>, <span style="color: #660033; font-weight: bold;">$outputFilePath</span><span style="color: #333;">&#41;</span> <br />
<span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Simplistic error handling</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$xslFilePath</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">resolve-<span style="font-style: normal;">path</span></span> <span style="color: #660033; font-weight: bold;">$xslFilePath</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span> <span style="color: #000066;">-not</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">test-<span style="font-style: normal;">path</span></span> <span style="color: #660033; font-weight: bold;">$xslFilePath</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">throw</span> <span style="color: #009900;">&quot;Can't find the XSL file&quot;</span> <span style="color: #333;">&#125;</span> <br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$originalXmlFilePath</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">resolve-<span style="font-style: normal;">path</span></span> <span style="color: #660033; font-weight: bold;">$originalXmlFilePath</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span> <span style="color: #000066;">-not</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">test-<span style="font-style: normal;">path</span></span> <span style="color: #660033; font-weight: bold;">$originalXmlFilePath</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">throw</span> <span style="color: #009900;">&quot;Can't find the XML file&quot;</span> <span style="color: #333;">&#125;</span> <br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$outputFilePath</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">resolve-<span style="font-style: normal;">path</span></span> <span style="color: #660033; font-weight: bold;">$outputFilePath</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span> <span style="color: #000066;">-not</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">test-<span style="font-style: normal;">path</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">split-<span style="font-style: normal;">path</span></span> <span style="color: #660033; font-weight: bold;">$originalXmlFilePath</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">throw</span> <span style="color: #009900;">&quot;Can't find the output folder&quot;</span> <span style="color: #333;">&#125;</span> <br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Get an XSL Transform object (try for the new .Net 3.5 version first)</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$EAP</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$ErrorActionPreference</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$ErrorActionPreference</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;SilentlyContinue&quot;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$script</span>:xslt <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> system.<span style="color: #003366; font-weight: bold;">xml</span>.<span style="color: #003366;">xsl</span>.<span style="color: #003366;">xslcompiledtransform</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">trap</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Management</span>.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">PSArgumentException</span><span style="color: #333;">&#93;</span></span> <br />
&nbsp; &nbsp;<span style="color: #333;">&#123;</span> &nbsp;<span style="color: #666666; font-style: italic;"># no 3.5, use the slower 2.0 one</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$ErrorActionPreference</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$EAP</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$script</span>:xslt <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> system.<span style="color: #003366; font-weight: bold;">xml</span>.<span style="color: #003366;">xsl</span>.<span style="color: #003366;">xsltransform</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$ErrorActionPreference</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$EAP</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## load xslt file</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$xslt</span>.<span style="color: #003366;">load</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$xslFilePath</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## transform </span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$xslt</span>.<span style="color: #003366;">Transform</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$originalXmlFilePath</span>, <span style="color: #660033; font-weight: bold;">$outputFilePath</span> <span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/convert-xml-with-xslt-in-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

