473,785 Members | 2,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Applying xslt stylesheet to ONLY resulting nodes? Help!

25 New Member
Hello, I need some help to solve the following problem (if it is possible, that's it):
I'm using a xpath expression to programatically get data from my xml file. I want to transform ONLY the resulting nodes using xslt. In my example below I only want the Academic category to be transformed.

Is this possible? (please vb.net or c#). Many thanks.
My xml file:
<categories>
<category>
<categorynumber >1</categorynumber>
<categoryname>A cademic</categoryname>
<dateadded>04/10/2007</dateadded>
</category>
<category>
<categorynumber >2</categorynumber>
<categoryname>M anagement and professional jobs</categoryname>
<dateadded>05/10/2007</dateadded>
</category>
<category>
<categorynumber >3</categorynumber>
<categoryname>R esearch</categoryname>
<dateadded>06/10/2007</dateadded>
</category>
</categories>

My xslt file:
<xsl:template match="category ">
<html>
<body>
<H2>Job categories</H2>
<table>
<tr>
<td>Number</td>
<td>Name</td>
<td>Date</td>
</tr>
<tr>
<td><xsl:valu e-of select="categor ynumber"/></td>
<td><xsl:valu e-of select="categor yname"/></td>
<td><xsl:valu e-of select="dateadd ed"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

My vb.net code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load

Dim doc As XmlDocument = New XmlDocument()
doc.Load("c:\AS PNetProjects\Jo bEmailAlert\XML Categories.xml" )

Dim navigator As XPathNavigator = doc.CreateNavig ator

Dim xslt As XslTransform = New XslTransform()
xslt.Load("c:\A SPNetProjects\J obEmailAlert\XS LT_TestCategori es.xsl")

Dim path As String = ("//category[categoryname = 'Academic']")

Dim nodeList As XmlNodeList = doc.SelectNodes (path)

Dim Vacancy As XmlNode

For Each Vacancy In nodeList

Dim output As StringWriter
output = New StringWriter()

xslt.Transform( navigator, Nothing, output)
lblOutput.Text = output.ToString ()
output.Close()

Next

End Sub
Oct 4 '07 #1
2 2364
jkmyoung
2,057 Recognized Expert Top Contributor
You could switch your current template to be like:
<xsl:template match="category[categoryname='A cademic']">
...

Create another single element template to pick up and suppress the rest of the categories.
<xsl:template match="category[categoryname!=' Academic']"/>

In terms of passing in a xml fragment to be transmitted, you would have to create a seperate xmlDocument or source from the nodelist to pass it in.
Oct 4 '07 #2
milecimm
25 New Member
My Xpath expression also includes date comparison which I understand is not supported by xslt.
Thanks anyway
milecimm
Oct 5 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2748
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a straight XML file http://www.discovertravelandtours.com/test/templates/test.xml?Location=Germany To another XML file http://www.discovertravelandtours.com/test/templates/test2.xml?Location=Germany
4
8119
by: cyclops | last post by:
I'm trying to do XML + XSLT -> Another XML. The source XML contains multiple namespaces and XSLT will handle all possible tags under each name space. ----source---- <document xmlns="..." xmlns:a="..." xmlns:b=""> .... ----XSLT---- ....
4
1832
by: Chris Kettenbach | last post by:
Hi Peter, I get error when processing the stylesheet. It errors here. <xsl:for-each select="registration)=1]"> specifically: Expression does not return a DOM node. registration)=1]<--
4
5250
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); } if (x) {
3
9927
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ========================= <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"
3
1761
by: Simon Brooke | last post by:
I've been doing XSL transforms, converting XML to HTML, server side since 2000. In those days, clients which could do the transformation client side didn't exist, so whether to transform client-side or server-side wasn't an issue. Recently I've been overhauling the code in order to pass transform to the client wherever possible, and I've hit two problems (i) How do I know whether the client can do transforms? Currently I'm only...
18
2087
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1 and A2 and feature B depends on B1 and B2. And write that to a text file.
4
2144
by: simon.a.hulbert | last post by:
Hi, I'm trying to view the following xslt transformation using firefox <xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" > <xsl:output method = "xml" indent = "yes" /> <xsl:attribute-set name = "set1" > <xsl:attribute name = "a" >1</xsl:attribute> <xsl:attribute name = "b" >2</xsl:attribute> </xsl:attribute-set> <xsl:attribute-set name = "set2" >
0
9645
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10091
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.