473,378 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

xslt transformation and input paths

Dan
I have a C# program which executes some XSLT transformations. The XSLT code
requires an input intermediate file, generated by other transformations, as
its duty is copying some data from an input XML while inserting into it
another XML fragment. E.g. let's say this is the original XML:

<Dummy>
<contacts>
... contacts go here ...
</contacts>
</Dummy>

We have then a fragment named ~new.xml:

<header>
<title>That's a dummy sample</title>
</header>

The corresponding XSLT should insert the <header> contents into the original
XML file, e.g.:

<xsl:template match="Dummy">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="document('~new.xml')//header"/>
<xsl:copy-of select="contacts"/>
</xsl:copy>
</xsl:template>

The XSLT above assumes that there is a file named ~new.xml in its path. But
my XSLT does NOT reside in a path as a file, it's stored as a resource in my
application assembly. Now **my question is**: how can the XslTransform
object know where to locate the ~new.xml file fragment, as it is loaded from
an assembly and the location of the original XML varies so that it is known
only at runtime? Is there any way to give it a default input path, or any
other solution to let the code work?

Here's the snippet which loads and executes the XSLT: it works fine, but it
fails to locate the ~new.xml fragment...:

XslTransform xslt = new XslTransform();
XmlUrlResolver res = new XmlUrlResolver();
res.Credentials = System.Net.CredentialCache.DefaultCredentials;
Assembly a = Assembly.GetExecutingAssembly();
Stream st =
a.GetManifestResourceStream("MyNamespace.xslt.MyTr ansform.xslt");
xslt.Load(new XmlTextReader(new StreamReader(st, Encoding.UTF8)), null,
null);
xslt.Transform(theSourceFile, theTargetFile, res); //<< how to tell it
where to locate ~new.xml?

Thx guys!
Nov 15 '05 #1
1 1578
Hi Dan,

You may the second XML file "~new.xml" in the same folder as your original
XML file, or specify the URI in the XSL file's Document function.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 15 '05 #2

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

Similar topics

9
by: Christian Roth | last post by:
Hello, when using this "identity" processing sheet: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="iso-8859-1" /> ...
6
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...
1
by: Jens Mueller | last post by:
Hi there, this is a Java-XML Question, so I am not sure whether this is the right place, haven't found anything better .... I try to convert a Java object to XML via SAX and let the FOP...
4
by: titanandrews | last post by:
Hi, I have ran into a situation that I think should be possible, but I am fairly new to XSLT so maybe not. Suppose I have the following document <ROOT> <FOO name="A"> <CHILD name="B"/>...
4
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 =...
6
by: JJBean | last post by:
Hi Oleg and All, Is this correct? Can I do this? <code> XmlDocument doc=new XmlDocument(); XPathNavigator nav = doc.CreateNavigator(); //Load the xml file. Change path if needed...
2
by: RJN | last post by:
Hi Can XSLT be applied for transforming .txt files or are they applicable only for xml to xml transformation. Currently all the clients send file to a server in one particular format. The...
15
by: Jeff Uchtman | last post by:
Can I draw from 2 XML sources, the structure is exactly the same execpt for data contained into 1 xslt using math to add some structrure, and displaying others as node 1 and node 2? This data is...
2
by: Jonny B | last post by:
Hi all, I'm working on an a clientside xslt using jscript that passes a parameter to the xsl. I've got it working no problem in IE but cant get it to work in Mozilla. Can anyone help? This is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.