Passing parameters to XSLT Stylesheet via .NET

You need to define the parameter within your XSLT and you also need to pass the XsltArgumentList as an argument to the Transform call: private static void CreateHierarchy(string manID) { string man_ID = manID; XsltArgumentList argsList = new XsltArgumentList(); argsList.AddParam(“Boss_ID”, “”, man_ID); XslCompiledTransform transform = new XslCompiledTransform(true); transform.Load(“htransform.xslt”); using (StreamWriter sw = new StreamWriter(“output.xml”)) { … Read more

Import ‘xml’ into Sql Server

Try this: DECLARE @XML XML = ‘<EventSchedule> <Event Uid=”2″ Type=”Main Event”> <IsFixed>True</IsFixed> <EventKind>MainEvent</EventKind> <Fields> <Parameter Name=”Type” Value=”TV_Show”/> <Parameter Name=”Name” Value=”The Muppets”/> <Parameter Name=”Duration” Value=”00:30:00″/> </Fields> </Event> <Event Uid=”3″ Type=”Secondary Event”> <IsFixed>True</IsFixed> <EventKind>SecondaryEvent</EventKind> <Fields> <Parameter Name=”Type” Value=”TV_Show”/> <Parameter Name=”Name” Value=”The Muppets II”/> <Parameter Name=”Duration” Value=”00:30:00″/> </Fields> </Event> </EventSchedule>’ SELECT EventUID = Events.value(‘@Uid’, ‘int’), EventType = Events.value(‘@Type’, … Read more

How to query xml column in tsql

How about this? SELECT EventID, EventTime, AnnouncementValue = t1.EventXML.value(‘(/Event/Announcement/Value)[1]’, ‘decimal(10,2)’), AnnouncementDate = t1.EventXML.value(‘(/Event/Announcement/Date)[1]’, ‘date’) FROM dbo.T1 WHERE t1.EventXML.exist(‘/Event/Indicator/Name[text() = “GDP”]’) = 1 It will find all rows where the /Event/Indicator/Name equals GDP and then it will display the <Announcement>/<Value> and <Announcement>/<Date> for those rows. See SQLFiddle demo

how to create an InputStream from a Document or Node

ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Source xmlSource = new DOMSource(doc); Result outputTarget = new StreamResult(outputStream); TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget); InputStream is = new ByteArrayInputStream(outputStream.toByteArray());

How can I select the first element using XSLT?

If you wish to output XHTML 1.1, here’s one way: <?xml version=”1.0″?> <xsl:transform version=”2.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:xs=”http://www.w3.org/2001/XMLSchema” exclude-result-prefixes=”xsl xs”> <xsl:output mode=”xhtml” version=”1.1″ omit-xml-declaration=”yes” encoding=”utf-8″ media-type=”application/xhtml+xml” indent=”no” doctype-public=”-//W3C//DTD XHTML 1.1//EN” doctype-system=”http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd” /> <xsl:template match=”//newsItem[1]”> <div><xsl:value-of select=”dateCreated”/></div> <div><xsl:value-of select=”summary”/></div> </xsl:template> </xsl:transform>

java.net.URISyntaxException

A valid URI does not contain backslashes, and if it contains a : then the characters before the first : must be a “protocol”. Basically “C:\Documents and Settings\All Users\.SF\config\sd.xml” is a pathname, and not a valid URI. If you want to turn a pathname into a “file:” URI, then do the following: File f = … Read more