<?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>Harvesting web technologies &#187; XSLT</title>
	<atom:link href="http://www.webfarmr.eu/tag/xslt/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webfarmr.eu</link>
	<description>SOA, Security, Cloud, XML, XSLT, XML Security Gateways, WS-*, XACML, web services</description>
	<lastBuildDate>Wed, 01 Feb 2012 11:21:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>XACML 102 – Pimp my XACML – Part II: with XSLT</title>
		<link>http://www.webfarmr.eu/2010/12/xacml-102-pimp-my-xacml-part-ii-with-xslt/</link>
		<comments>http://www.webfarmr.eu/2010/12/xacml-102-pimp-my-xacml-part-ii-with-xslt/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 16:51:35 +0000</pubDate>
		<dc:creator>David Brossard</dc:creator>
				<category><![CDATA[XACML Bites]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[xalan]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://www.webfarmr.eu/?p=160</guid>
		<description><![CDATA[In my previous post on making XACML look pretty, we had a look at a very simple and easy way to add some colors / borders / general style to the XML via CSS. The CSS was interpreted by your browser and the result displayed there.
CSS is simple and straightforward but it is also limited (not to  [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous <a href="http://www.webfarmr.eu/2010/11/xacml-102-pimp-my-xacml-css/" target="_self">post</a> on making XACML look pretty, we had a look at a very simple and easy way to add some colors / borders / general style to the XML via CSS. The CSS was interpreted by your browser and the result displayed there.</p>
<p>CSS is simple and straightforward but it is also limited (not to mention it is probably not the most adequate tool for our purpose). The next level up is to use <a href="http://www.w3.org/TR/xslt" target="_blank">XSLT</a> (part of the <a title="The Extensible Stylesheet Language Family (XSL)" href="http://www.w3.org/Style/XSL/" target="_blank">W3C XSL group of standards</a>).</p>
<p>At our level, in a very reductive and simple way, the key difference between CSS and XSLT is that CSS doesn&#8217;t touch the XML source. It merely adds style. XSLT, on the other hand, transforms the XML source into another XML document which can be totally different in structure. This means that we can convert XACML into HTML (and lose all sense of Policy, PolicySet, Rule elements).</p>
<p>There are two ways XSLT can be applied: either by an XSLT processor e.g. <a href="http://xml.apache.org/xalan-j/" target="_blank">Xalan</a> or via the processor of your browser. In our example below, we will be using Xalan from the command line to generate a sample HTML document from a XACML policy.</p>
<p>Before I carry on, I would like to thank my colleagues at <a href="http://www.axiomatics.com/" target="_blank">Axiomatics</a>, Erik &amp; Pablo, who kindly accepted to give me a hand write the XSLT while we were flying back to Sweden from a business trip in the City of London.</p>
<p>We will be using the same <a href="http://www.webfarmr.eu/wp-content/uploads/2010/11/eat-fruit.xml">eat-fruit</a> policy as in the previous post. I also decided to use Xalan to run the transformations.</p>
<p>Checklist:</p>
<ol>
<li>Download <a href="http://xml.apache.org/xalan-j/" target="_blank">Xalan</a> and unzip in your favorite location.</li>
<li>[optional] Write a little <a href="http://www.webfarmr.eu/wp-content/uploads/2010/12/build.xml" target="_self">ant script</a> to ease the invocation of the xalan engine. This requires that you download ant too.</li>
<li>Download the <a href="http://www.webfarmr.eu/wp-content/uploads/2010/11/eat-fruit.xml">eat-fruit</a> policy.</li>
<li>Download the <a href="http://www.webfarmr.eu/wp-content/uploads/2010/12/style-xhtml.xsl">style-xhtml</a> XSLT stylesheet. See source below which can be copy-pasted for convenience.</li>
</ol>
<pre class="brush: xml; light: false; title: ; toolbar: true; notranslate">
&lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot; xmlns:xacml3=&quot;urn:oasis:names:tc:xacml:3.0:core:schema:wd-17&quot; version=&quot;1.0&quot;&gt;
&lt;xsl:output method=&quot;html&quot; indent=&quot;yes&quot;/&gt;

&lt;xsl:template match=&quot;/&quot;&gt;
				&lt;xsl:apply-templates/&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match=&quot;/&quot;&gt;
	&lt;html&gt;
		&lt;head&gt;
			&lt;link href=&quot;style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;/&gt;
		&lt;/head&gt;
			&lt;body&gt;

				&lt;xsl:apply-templates/&gt;
			&lt;/body&gt;
	&lt;/html&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match=&quot;xacml3:Policy|xacml3:PolicySet&quot;&gt;
	&lt;div&gt;
		&lt;xsl:value-of select=&quot;@PolicyId|@PolicySetId&quot;/&gt;
		&lt;xsl:apply-templates/&gt;
	&lt;/div&gt;
&lt;/xsl:template&gt;

&lt;xsl:template match=&quot;text()&quot;&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match=&quot;xacml3:Rule&quot;&gt;
	&lt;div class=&quot;{@Effect}&quot;&gt;
		&lt;xsl:value-of select=&quot;@RuleId&quot;/&gt;
	&lt;/div&gt;
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>
<p>Assuming you have ant configured and on your classpath, you can then execute the following command:</p>
<pre>ant xslt -Dxsl=style-xhtml.xsl -Din=in.xml -Dout=out.html
</pre>
<p>What you then get is something along these lines:</p>
<div id="attachment_167" class="wp-caption alignnone" style="width: 160px"><a href="http://www.webfarmr.eu/wp-content/uploads/2010/12/eat-fruit-html.png"><img class="size-thumbnail wp-image-167" title="eat-fruit-html" src="http://www.webfarmr.eu/wp-content/uploads/2010/12/eat-fruit-html-150x150.png" alt="HTML page generated using XSLT and XACML as source XML" width="150" height="150" /></a><p class="wp-caption-text">HTML page generated using XSLT and XACML as source XML</p></div>
<p>Of course, this looks extremely similar to what we had done with CSS. However, if we look at the source, it is drastically different:</p>
<pre class="brush: xml; light: false; title: ; toolbar: true; notranslate">&lt;html xmlns:xacml3=&quot;urn:oasis:names:tc:xacml:3.0:core:schema:wd-17&quot;&gt;
&lt;head&gt;
&lt;META http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div&gt;eat-fruit&lt;div&gt;citrus&lt;/div&gt;
&lt;div&gt;berry&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Check out the XSLT to understand how it works. There are plenty of books on the topic. Here&#8217;s one of them.<div style="clear:both"><div style="float:left;padding-right:10px;padding-bottom:10px;"><a href='http://openlibrary.org/books/OL7580889M/Xslt' ><img src='http://covers.openlibrary.org/b/id/388467-M.jpg' alt='Xslt' title='View this title in Open Library' /></a></div><div style="font-size:18px;font-weight:bold;"><a href='http://openlibrary.org/books/OL7580889M/Xslt' title='View this title in Open Library' >Xslt</a></div><div style="font-size:14px;"><a href='http://openlibrary.org/authors/OL2726775A/Doug_Tidwell' title='View this author in Open Library' >Doug Tidwell</a>; O&#039;Reilly Media, Inc. 2001</div><div style="font-size:10px;"><a href="http://worldcat.org/isbn/9780596000530" title="View this title at WorldCat">WorldCat</a>&#8226;<a href="http://www.librarything.com/work/16862" title="View this title at LibraryThing">LibraryThing</a>&#8226;<a href="http://books.google.com/books?as_isbn=9780596000530" title="View this title at Google Books">Google Books</a>&#8226;<a href="http://www.bookfinder.com/search/?st=xl&ac=qr&isbn=9780596000530" title="Search for the best price at BookFinder">BookFinder</a></div><span class="Z3988" title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rfr_id=info%3Asid%2Fwww.webfarmr.eu%3AOpenBook&amp;rft.genre=book&amp;rft.btitle=Xslt&amp;rft.isbn=9780596000530&amp;rft.au=Doug+Tidwell&amp;rft.pub=O%26%23039%3BReilly+Media%2C+Inc.&amp;rft.date=August+15%2C+2001&amp;rft.tpages=478"></span></div></p>
<p>The next step is two-fold:</p>
<ol>
<li>either use Javascript + CSS (AJAX) to enhance the HTML output</li>
<li>or use other XML languages that more graphical (OpenLazslo or SVG).</li>
</ol>
<p>Until then, Merry Christmas!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webfarmr.eu/2010/12/xacml-102-pimp-my-xacml-part-ii-with-xslt/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Replace an XML element value using XSLT</title>
		<link>http://www.webfarmr.eu/2008/10/replace-an-xml-element-value-using-xslt/</link>
		<comments>http://www.webfarmr.eu/2008/10/replace-an-xml-element-value-using-xslt/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 08:40:21 +0000</pubDate>
		<dc:creator>David Brossard</dc:creator>
				<category><![CDATA[Identity & Access Management]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[ws-addressing]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSL]]></category>
		<category><![CDATA[XSLT]]></category>

		<guid isPermaLink="false">http://www.webfarmr.eu/webfarmr/?p=3</guid>
		<description><![CDATA[The aim is to take a document, look for a specific element (by local name and URI rather than name including prefix) and replace its value.
Where is this useful? Imagine a gateway protecting an internal web service. If that web service is WS-A enabled, it therefores has a wsa:From field which  [...]]]></description>
			<content:encoded><![CDATA[<p>The aim is to take a document, look for a specific element (by local name and URI rather than name including prefix) and replace its value.</p>
<p>Where is this useful? Imagine a gateway protecting an internal web service. If that web service is WS-A enabled, it therefores has a wsa:From field which contains its internal URI. Obviously the gateway abstracts the internal service from what is seen outside as a &#8216;virtual&#8217; or &#8216;logical&#8217; service. One therefore needs to update the wsa:From field to reflect an external URI.</p>
<p>Sample XML:</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;soap12:Envelope xmlns:soap12=&#8221;http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:xsd=&#8221;http://www.w3.org/2001/XMLSchema&#8221; xmlns:xsi=&#8221;http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns:wsa05=&#8221;http://www.w3.org/2005/08/addressing&#8221; xmlns:uddi=&#8221;urn:uddi-org:api_v2&#8243; xmlns:ns1=&#8221;http://ws.samples.engage.bt.com&#8221; xsi:schemaLocation=&#8221;http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/&#8221;&gt;<br />
&lt;soap12:Header&gt;<br />
&lt;wsa05:To&gt;http://somelocation&lt;/wsa05:To&gt;<br />
&lt;wsa05:Action&gt;urn:greet&lt;/wsa05:Action&gt;<br />
&lt;wsa05:From&gt;<br />
&lt;wsa05:Address&gt;http://internaluri.intra.mycompany.com&lt;/wsa05:Address&gt;<br />
&lt;/wsa05:From&gt;<br />
&lt;/soap12:Header&gt;<br />
&lt;soap12:Body&gt;<br />
&lt;ns1:greet soap12:encodingStyle=&#8221;http://schemas.xmlsoap.org/soap/encoding/&#8221;&gt;<br />
&lt;in0 xsi:type=&#8221;xsd:string&#8221;&gt;Philip&lt;/in0&gt;<br />
&lt;/ns1:greet&gt;<br />
&lt;/soap12:Body&gt;<br />
&lt;/soap12:Envelope&gt;</p>
<p>The XSL to be applied here is</p>
<p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;xsl:stylesheet version=&#8221;2.0&#8243; xmlns:xsl=&#8221;http://www.w3.org/1999/XSL/Transform&#8221; xmlns:xs=&#8221;http://www.w3.org/2001/XMLSchema&#8221; xmlns:fn=&#8221;http://www.w3.org/2005/xpath-functions&#8221; xmlns:soapenv=&#8221;http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:wsa=&#8221;http://www.w3.org/2005/08/addressing&#8221;&gt;<br />
&lt;xsl:output method=&#8221;xml&#8221; version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243; indent=&#8221;yes&#8221;/&gt;<br />
&lt;xsl:variable name=&#8221;fromVirtualUri&#8221;&gt;http://virtualFromValue&lt;/xsl:variable&gt;<br />
&lt;xsl:template match=&#8221;node()|@*&#8221;&gt;<br />
&lt;xsl:copy&gt;<br />
&lt;xsl:choose&gt;<br />
&lt;xsl:when test=&#8221;local-name()=&#8217;Address&#8217;&#8221;&gt;<br />
&lt;xsl:if test=&#8221;namespace-uri()=&#8217;http://www.w3.org/2005/08/addressing&#8217;&#8221;&gt;<br />
&lt;xsl:value-of disable-output-escaping=&#8221;yes&#8221; select=&#8221;$fromVirtualUri&#8221;&gt;&lt;/xsl:value-of&gt;<br />
&lt;/xsl:if&gt;<br />
&lt;/xsl:when&gt;<br />
&lt;xsl:otherwise&gt;<br />
&lt;xsl:apply-templates select=&#8221;@*|*|processing-instruction()|comment()|text()&#8221;&gt;<br />
&lt;xsl:with-param name=&#8221;virtualUri&#8221;&gt;&lt;/xsl:with-param&gt;<br />
&lt;/xsl:apply-templates&gt;<br />
&lt;/xsl:otherwise&gt;<br />
&lt;/xsl:choose&gt;<br />
&lt;/xsl:copy&gt;<br />
&lt;/xsl:template&gt;<br />
&lt;/xsl:stylesheet&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webfarmr.eu/2008/10/replace-an-xml-element-value-using-xslt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

