<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://draft.blogger.com/navbar.g?targetBlogID\x3d8211560\x26blogName\x3dTech+Tips,+Tricks+%26+Trivia\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://mvark.blogspot.com/search\x26blogLocale\x3den\x26v\x3d2\x26homepageUrl\x3dhttp://mvark.blogspot.com/\x26vt\x3d-5147029996388199615', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
An architect's notes, experiments, discoveries and annotated bookmarks.

Search from over a hundred HOW TO articles, Tips and Tricks


Fetch records selectively from XML file by passing dynamic value through XSL

This code snippet called on Page_Load shows how to selectively pick records from a XML file based on a dynamic value passed through XSL and doing a transformation in C# . Needs a little more fine tuning.... XsltArgumentList does the trick!

string node = Request.QueryString["country"];
if (node!=null)
{
XmlDocument docXml = new XmlDocument();
docXml.Load(Server.MapPath("users.xml"));
XslTransform docXsl = new XslTransform();
docXsl.Load(Server.MapPath("users.xsl"));

XsltArgumentList xslarg = new XsltArgumentList();
xslarg.AddParam("country", "", node);

docXsl.Transform(docXml, xslarg, Response.Output);
}
else
{
Response.Write("Parameter missing");
}
}



users.xml



<users>
<user>
<name>Anil</name>
<city>Hyderabad</city>
<country>India</country>
</user>
<user>
<name>Moe</name>
<city>New York</city>
<country>USA</country>
</user>
</users>


users.xsl


<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="country"></xsl:param>
<xsl:template match="users">

<html><head>
<title>Users</title></head>
<body>

<xsl:for-each select="user">
<xsl:if test="country=$country">

<b><xsl:value-of select="city"></xsl:value-of></b>


</xsl:if>
</xsl:for-each>

</body>
</html>

</xsl:template>
</xsl:stylesheet>



I found the sample on Paging Through XML Records using ASP.NET and XSLT useful.

Labels:

Tweet this | Google+ it | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »

»

Post a Comment