Archive for the category “XML-XSLT”

September 16th, 2004 at 5:25 am

XSLT + .Net and Must have tools

Links to,

XSLT with .Net - code generation techniques

10 Must have tools

May 1st, 2006 at 9:01 am

XSL transform with arguments

Using XsltArgumentList, we can pass arguments or variable values in to the XSLT while transforming an Xml document. One can also pass in another stream of Xml document such that the XSLT operates on two Xml documents at once.
Following is a piece of code that makes it happen in C#. It also passes in a parameter to sort a column in the Xml document.

XslCompiledTransform xslt = new XslCompiledTransform();

XmlReader xReader = XmlReader.Create(new StringReader(Properties.Resources.XsltFile));

xslt.Load(xReader);

StringWriter stringOut = new StringWriter();

XsltArgumentList xsltArgs = new XsltArgumentList();

xsltArgs.AddParam(“extraXmlDocument”, string.Empty, xpathNavigableObject.CreateNavigator());

if (!string.IsNullOrEmpty(sortBy))

{

xsltArgs.AddParam(“sortBy”, string.Empty, sortBy);

if (sortType.Trim().Equals(“down”))

{

sortType = “descending”;

}

else

{

sortType = “ascending”;

}

xsltArgs.AddParam(“sortType”, string.Empty, sortType);

}

else

{

xsltArgs.AddParam(“sortBy”, string.Empty, string.Empty);

xsltArgs.AddParam(“sortType”, string.Empty, “ascending”);

}

xslt.Transform(xpathNavigableObject, xsltArgs, stringOut);

// Set the new sorted html content back to the webbrowser control’s html.

// Just an example below.

m_webBrowser.Document.Body.InnerHtml = stringOut.ToString();

Notes: Always use “XslCompiledTransform” and ‘XpathDocument‘ when you need readonly access.

January 26th, 2006 at 12:14 pm

The “true” Checklist for XML Performance

http://monkey.workarea.jp/lb/archive/2005/8-08.html

March 1st, 2006 at 8:45 am

String replace in XSLT

It is possible to do string manipulation like replace etc in XSLT as well. Javascript has str.replace right? So in XSLT you can do this by creating templates and by doing call-template.

Follow this link for complete info and source code
http://www.dpawson.co.uk/xsl/sect2/StringReplace.html

December 1st, 2004 at 11:26 am

Check for nodename in XSLT

Its always necessary sometimes in XSLT processing that we check for things like whether a node exists to do certain operations. Checking for nodenames is the clue. This is how you do it.

<xsl:variable name=”varname”>
<xsl:value-of select=”ParentNode/*[name()='childnodename to check for']“/>
<xsl:variable>
<xsl:if test=”$varname=””> Processing here…
<xsl:if>