Showing posts with label xsl. Show all posts
Showing posts with label xsl. Show all posts

Wednesday, November 18, 2009

XSLT transformation using Javascript

<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery.xslt.js" type="text/javascript"></script>
<script language='javascript'>

$(document).ready(function() {

var waitMessage = "<table width='100%' align='center'>" +
"<tr><td align='center'><img src='Your img'/></td></tr></table>";
$('#outResults').html(waitMessage);
var xsltUrl = 'Your xslt url here';
var xmlUrl = 'Your xml url here';

//load xml url
$.get(xmlUrl,{},
function(data, txtStatus){

//load xslt url
var xml = data.xml;
//load xslt url
$.get(xsltUrl,{},
function(data2, txtStatus2){

var xslt = data2.xml;
$('#outResults').xslt(xml, xslt);

}, "xml");

}, "xml");

}); //document ready

</script>

<div id="outResults"></div>

Monday, November 2, 2009

XSL Parameters

Firstly, remember that once you assign content to a named parameter (xsl:param or xsl:variable), that element is immutable.

Assign value to xsl:param
<xsl:param name="last_name">Cagle</xsl:param>

Retrieve value of xsl:param
<last_name><xsl:value-of select="$last_name"/></last_name>

Assign XML tags to xsl:param
<xsl:param name="person">
<record>
<first_name>Kurt</first_name>
<last_name>Cagle</last_name>
<vocation>Writer</vocation>
</record>
</xsl:param>

If you use <xsl:value-of select="$person"/>, the output stream is: KurtCagleWriter

<xsl:copy-of select="$person"/> lets you output the whole XML Structure:
<record>
<first_name>Kurt</first_name>
<last_name>Cagle</last_name>
<vocation>Writer</vocation>
</record>

Reference & More on this topic: http://msdn.microsoft.com/en-us/library/ms950787.aspx

Sunday, November 1, 2009

Grouping Using the Muenchian Method

Reference: http://www.jenitennison.com/xslt/grouping/muenchian.html

How do you take a list of elements and arrange them into groups in your XSLT stylesheet?

Sample XML
<records>

    <contact id="0001">

        <title>Mr</title>

        <forename>John</forename>

        <surname>Smith</surname>

    </contact>

    <contact id="0002">

        <title>Dr</title>

        <forename>Amy</forename>

        <surname>Jones</surname>

    </contact>

    ...

</records>

Desired Outcome


 


 

Jones,<br />

    Amy (Dr)<br />

    Brian (Mr)<br />

Smith,<br />

    Fiona (Ms)<br />

    John (Mr)<br />


The Muenchian Method is a method developed by Steve Muench for performing these functions in a more efficient way using keys. Keys work by assigning a key value to a node and giving you easy access to that node through the key value. If there are lots of nodes that have the same key value, then all those nodes are retrieved when you use that key value. Effectively this means that if you want to group a set of nodes according to a particular property of the node, then you can use keys to group them together.

How to put XSLT tag inside HTML element

For example, how to generate <A HREF="http://mypage.html">home page</A> in HTML where link is provided from XML file.

Use AVTs (attribute value templates) for most simple expressions.
AVTs are expressions within attributes enclosed with {} curly braces, e.g.

<A HREF="{/bio/homepage}">home page</A>

When you need to generate the value of an attribute using more complex XSLT
(e.g. the value is to be built using template calls or the like) then you
can use the instruction, e.g.

<A>
<xsl:attribute name="HREF">
<xsl:call-template name="build-the-href"/>
</xsl:attribute>
<xsl:text>home page</xsl:text>
</A>

Wednesday, October 21, 2009

Check for null value in XSL File

If you want to check if an element exists, you can do...
<xsl:if test="/A/B/C">...</xsl:if>
That will test if the C element exists.

If you want to check if an element has empty content, you can do...
<xsl:if test="/A/B/C=''">...</xsl:if>