473,563 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using xpath with xslt ?

Hi,

I would like to use xpath with xslt. I know that this
should be possible, but I dont get it ! Here is what I
have tried so far:

=============== =============== ======
my xml file:
=============== =============== ======

<?xml version="1.0" encoding="utf-8"?>
<CategoryList >
<Category ID="01">
<MainCategory>X ML1</MainCategory>
<Description>Th is is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
<Category ID="02">
<MainCategory>X ML2</MainCategory>
<Description>Th is is a list my XML
articles.</Description>
<Active>true</Active>
</Category>
</CategoryList>
=============== =============== ======

my xsl file:

=============== =============== ======

<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:param name="strXPath" select="Categor y"/>
<xsl:template match="/">
<xsl:apply-templates select="$strXPa th">
<xsl:sort select="categor y" order="descendi ng"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="Category ">
<b>
<xsl:value-of select="MainCat egory"/><br/>
</b>
</xsl:template>
</xsl:stylesheet>

=============== =============== ======

my code:

=============== =============== ======

<%@ Import Namespace="Syst em.Data" %>
<%@ Import Namespace="Syst em.Xml" %>
<%@ Import Namespace="Syst em.Xml.XPath" %>
<%@ Import Namespace="Syst em.Xml.Xsl" %>
<%@ Import Namespace="Syst em.IO" %>
<%@ Page Language="C#" Debug="true" %>

<script runat="server">
void Page_Load(objec t sender, System.EventArg s e){
if(!Page.IsPost Back){
XPathDocument xpathDoc = new XPathDocument
(Server.MapPath ("categories.xm l"));

XslTransform xslt = new XslTransform();
xslt.Load( Server.MapPath( "categories.xsl ") );

XsltArgumentLis t arguments = new XsltArgumentLis t();

string xpath="Category List/Category[@ID='01']";
arguments.AddPa ram( "strXPath", "", "xpath");

XmlTextWriter writer = new XmlTextWriter
(Response.Outpu t);
xslt.Transform( xpathDoc, arguments, writer, null);
}
}
</script>

Thanks in advance, Sonu Kapoor
Nov 12 '05 #1
1 1464
Sonu Kapoor wrote:
I would like to use xpath with xslt. I know that this
should be possible, but I dont get it ! Here is what I
have tried so far:


In any compiled language you can't pass part of source code as a
parameter and expect it to run. XSLT isn't different, there is no
dynmaic XPath evaluation in XSLT.
Instead, select nodes you want to process using XPathNavigator and pass
them to XSLT as a parameter.

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2897
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for this, and came across a problem that I haven't been able to solve elegantly. The problem is to find "linker" vertexes that a pair of verteces from...
7
16637
by: Sebastian Petzelberger | last post by:
Hi group, please give me an example of a xpath with regex or better a link with examples. Thanks in advance, Sebastian
1
4024
by: DV | last post by:
Hello, can anyone tell me or point me to somewhere what the exact differences (in terms of when would I use what) between XPath, XLink, XPointer and DOM are? Does it require special software to use any of these, or can any XML-aware software (parser/validator or xsl- enginge) use any of these?
14
12144
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following line in xslt <xsl:value-of select="/blah/q" /> and my xml document does not have a node /blah/q. The output would
6
2148
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows XP Pro SP 1, .Net Framework 1.1) and on our production server (Windows 2K SP 4, .Net Framework 1.1). I have simplified the code and data to isolate...
3
1913
by: Greg | last post by:
Hi, I want to create a web based interface that uses a form + Javascript (in an XHTML namespace) to construct an XPath to query and modify the attributes of some SVG (in an SVG namespace). There are lots of Google hits on each of these specifications and related technology, shuch as namespaces but there's almost nothing I can find that...
1
1512
by: Oleg Paraschenko | last post by:
Hello, those who are still interested in "lisp vs xml" and "xml is a poor copy of s-expressions" issues, might find my recent writings interesting: Towards s-expression based XPath/XSLT implementation http://xmlhack.ru/protva/xquery/index.php/TowardsXslt Abstract:
1
2404
by: Sergey Dubinets | last post by:
In effort to prioritize our goals we composed the list of random features each of them may add value to set of XSLT tools offered from Microsoft. 1. XSLTc (Compiler for XSLT stylesheets, that generates .NET assemblies) 2. Performance improvements in the XslCompiledTransform
2
2558
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all elements/attributes etc. defined but the values in these elements/attributes might be blank or place holders, as two examples below: Example - File type 1
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.