473,732 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple External References in Transfom

Having worked through the problems around enabling the document function
using an XmlUrlResolver I started work on building a useful class to hide
the intricacies.
Trying to generalise the process I've hit a snag.

How do I resolve multiple external references?

The transform method on a stylesheet only takes one resolver, not an array

Stephen
Nov 12 '05 #1
6 2487
Stephen Cook wrote:
How do I resolve multiple external references?

The transform method on a stylesheet only takes one resolver, not an array


What do you mean? Resolver object is supposed to resolve all external
references, not a single one.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
Aha!

Question becomes - How do I create multiple references within one resolver?

Stephen

"Oleg Tkachenko" <oleg@NO!SPAM!P LEASEtkachenko. com> wrote in message
news:eG******** ******@TK2MSFTN GP12.phx.gbl...
Stephen Cook wrote:
How do I resolve multiple external references?

The transform method on a stylesheet only takes one resolver, not an
array
What do you mean? Resolver object is supposed to resolve all external
references, not a single one.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #3
Long post - Posted to explain the background to the issue of resolvers,
highlight a couple of further points around evidences and resolution of
paths and hopefully provide a full example that is useful by way of
returning a little of the help I continue to receive from these sort's of
resources.

A bit of background for the casual reader.

The object of the exercise was to create a class that would create a regular
data island (no null attributes) from the output of SQLXML.
This is structured to support the built-in table binding of internet
explorer.

The following example is from my scratch routine, built while I explored the
..Net framework's XML library.
The output stream strmOutput is created externally.
You might use something like

XmlTextWriter writer = new XmlTextWriter(C onsole.Out);
writer.Formatti ng=Formatting.I ndented;
or
XmlTextWriter xtwDump = new
XmlTextWriter(" C:\\dumpXslTest .xml",System.Te xt.Encoding.UTF 8);
xtwDump.Formatt ing = Formatting.Inde nted;

in the web environment, to generate the data island use something like
strmOutput = new
StreamWriter(Ht tpContext.Curre nt.Response.Out putStream,Syste m.Text.Encoding .
UTF8,640);

Anyway all that stuff gets set up in the public methods before calling the
following
(Rest of routine needs re-factoring as presented here, but easier to explain
in one routine)

private Boolean prvTransformDat aset()
{
string strConn = "Database Connection";
// Reference to stylesheet to convert raw XMl into "regular" xml data
island that can be consumed by internet explorer's

table binding
string stylesheet =
"C:\\projects\\ projectfolder\\ BusinessObject\ \general.xslt"; //Point A
below

try
{
//Get the raw XML data
SqlXmlCommand cmd = new SqlXmlCommand(s trConn);
cmd.RootTag = "XML";
cmd.CommandText = "Select * from tablename for xml auto";
cmd.CommandType = SqlXmlCommandTy pe.Sql;
XmlReader xReader = cmd.ExecuteXmlR eader();

//Load into a suitable document
XPathDocument xpathdocument = new
XPathDocument(x Reader,XmlSpace .Preserve);

//Now set up the transform
XslTransform xslt = new XslTransform();
//Transform includes an external reference to a simplifed schema for the
output table
//Which is loaded as a variable in the stylesheet
//<xsl:variable name="Sch"
select="documen t('C:/projects/projectfolder/BusinessObject/tableschema.xml ')
" />
XmlUrlResolver xrsSchema = new XmlUrlResolver( );
Uri uriSchema = new Uri(stylesheet) ;
Uri uriFull = xrsSchema.Resol veUri(uriSchema ,"tableschema.x ml");
xslt.Load(style sheet); //Point B below

//Create an XsltArgumentLis t to pass in the parameterised tags
// A bindable data island has three levels
XsltArgumentLis t xslArg = new XsltArgumentLis t();
xslArg.AddParam ("Island","" , "dsoTableNameId ");
xslArg.AddParam ("Group","", "CollectionName ");
xslArg.AddParam ("Line","", "Data");

//Now ready to perform the transform
// Finally worked when I included the reference to the resolver here
rather than at stylesheet load
// I don't understand what causes the difference (I make mistakes??)
xslt.Transform( xpathdocument, xslArg, strmOutput, xrsSchema);
// Make sure we get the whole thing - Again this didn't appear to be
necessary.
strmOutput.Flus h();
return(true);
}
catch(Exception e)
{
XmlTextWriter txwError = new XmlTextWriter(C onsole.Error);
txwError.WriteR aw(("Error in try" + e.ToString()));
return(false);
}
finally
{
//Lots of tidy up in here
}
}

Point A.

This is the full transform (well something like it anyway)
This variant generates the data as attributes. It's not hard to convert to
generate data as tags (exercise for the reader)
Note that there is no namespace handling in here
All null attributes are generated
and all dates are translated in to a more human-friendly format

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transfor m xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xsl xs"
version="1.0">

<xsl:output method="xml" indent="yes"/>

<xsl:param name="Island" select="'island Id'"/>
<xsl:param name="Group" select="'collec tion'"/>
<xsl:param name="Line" select="'data'"/>
<xsl:variable name="Sch"
select="documen t('C:/projects/projectfolder/BusinessObject/tablename.xml') "
/>

<!--Match the root node -->
<xsl:template match="/">
<xsl:element name="xml">
<xsl:attribut e name="id">
<xsl:value-of select="$Island "/>
</xsl:attribute>
<xsl:element name="{$Group}" >
<xsl:apply-templates select="*|@*"/>
</xsl:element>
</xsl:element>
</xsl:template>

<!-- Match each data row -->
<xsl:template match="//tablename"> <!-- this could be a parameter too -->
<xsl:element name="{$Line}">
<!-- store this row in a variable -->
<xsl:variable name='row' select='.'/>
<!-- iterate through each field (from the s:Schema section) -->
<xsl:for-each
select="$Sch/xs:schema/xs:element[@name='lps_loca tion']/xs:complexType/xs:at
tribute">

<xsl:choose>
<!-- test for date time fields to permit extra conversion -->
<xsl:when test="@type='xs :dateTime'">
<!-- copy the name of this field into a variable -->
<xsl:variable name='fieldname ' select='@name'/>
<!-- output the element, and the data value as attribute-->
<xsl:attribut e name='{$fieldna me}'>
<!-- xsl:value-of select='$row/@*[name()=$fieldna me]'/ -->
<xsl:variable name="datevalue " select='$row/@*[name()=$fieldna me]'/>
<xsl:if test="$datevalu e!=''">
<xsl:value-of select="substri ng($datevalue,9 ,2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substri ng($datevalue,6 ,2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substri ng($datevalue,1 ,4)"/>
<xsl:text> </xsl:text>
<xsl:value-of

select="substri ng(substring-after($datevalu e,'T'),1,8)"/>
</xsl:if>
</xsl:attribute>
</xsl:when>
<xsl:otherwis e>
<!-- copy the name of this field into a variable -->
<xsl:variable name='fieldname ' select='@name'/>
<!-- output the element, and the data value as attribute -->
<xsl:attribut e name='{$fieldna me}'>
<xsl:value-of select='$row/@*[name()=$fieldna me]'/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>

</xsl:for-each>
</xsl:element>
</xsl:template>

</xsl:transform>

My schema looked somehing like this - you can see I was reading some
addressing data
Only the "required" fields appear by default from SQLXML.
If the values for the any of the other fields are null in the database, no
attribute is generate by SQLXML, so we want to add it.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" >
<xs:element name="SGC">
<xs:complexType >
<xs:sequence>
<xs:element ref="lps_locati on" maxOccurs="unbo unded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="lps_locat ion">
<xs:complexType >
<xs:attribute name="LOCATION_ ID" type="xs:short" use="required"/>
<xs:attribute name="INITIAL_L OCATION_ID" type="xs:short" use="required"/>
<xs:attribute name="PREDECESS OR_ID" type="xs:short" use="required"/>
<xs:attribute name="BUILDING" type="xs:string "/>
<xs:attribute name="ROAD" type="xs:string "/>
<xs:attribute name="DISTRICT" type="xs:string "/>
<xs:attribute name="CITY" type="xs:string "/>
<xs:attribute name="COUNTY" type="xs:string "/>
<xs:attribute name="ACTIVE" type="xs:string " use="required"/>
<xs:attribute name="CREATED_B Y" type="xs:string " use="required"/>
<xs:attribute name="CREATED_D ATE" type="xs:dateTi me" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
Point B.

I couldn't get any joy from using the overloaded "Load" method
(stylesheet,res olver).
Perhaps this is used to resolve the "xsl:import " and "xsl:includ e"
references????
Note that such an overload is now deprecated and advice appears to be to use
(stylesheet, resolver, evidence)
I didn't get a great deal of joy from evidence either.
Lots of confusion (for me) around http examples, where I was staying in the
middle tier and doing direct file access

I also found that having created this resolver I was getting good data from
both the identifed path and from "C:\tablename.x ml".
The resolver would "fail" for files of different names, but still let
through a file of the same name on either path.
I didn't expect this.
I would have thought that only the exact path I entered would be valid, not
any path in the same domain(???)
I haven't tested in more detail. Perhaps this is a case for sorting out a
credentials object or the evidence object???
Nov 12 '05 #4
Hi Stephen,

I'm currently researching on this issue and will update you as soon as I
get any progress.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #5
I assume your interested in the behaviour of the resolver.
Contact me directly if the full working example would be useful, rather than
the slightly mangled version presented here.

Many thanks for your interest

Stephen

"Kevin Yu [MSFT]" <v-****@online.mic rosoft.com> wrote in message
news:ms******** ******@cpmsftng xa06.phx.gbl...
Hi Stephen,

I'm currently researching on this issue and will update you as soon as I
get any progress.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #6
Hi Stephen,

We need to use the XmlResolver at different time based on different
situation. For example, to resolve with Document () function, we have to
use it with Transform function. For more information on this issue, you may
refer to:

http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconresolvinge xternalxsltstyl esheetsdocument s.asp

Luke
Microsoft Online Support

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

Nov 12 '05 #7

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

Similar topics

11
2389
by: Douglas Reith | last post by:
Hi There, Can someone please tell me why the XML spec states that an attribute value with an external entity is forbidden? Or point me to the appropriate document? Or better still, perhaps you know of a work around? It is a little frustrating that the normally powerful external entities are limited in this fashion. Example (myextent.txt contains just one word without a CR):
4
4025
by: blu4899 | last post by:
Hi, The Xerces XML parser is reading external DTD references in DOCTYPEs by default, but is not doing anything with them because validation is turned off by default. This is documented in http://xml.apache.org/xerces2-j/features.html#nonvalidating.load-external-dtd This setting causes many XML instances with broken DTD references in the DOCTYPE to fail and adds some performance overhead. Is there anything good that comes from this...
1
1998
by: S. van Beek | last post by:
Dear reader, In case an application is ussing an external model library you have to address this external model library in your application. This addressing takes place in a module of the application by opening of a module and activates and than brows to the location of the external library.
2
2859
by: Johann Blake | last post by:
I can hardly believe I'm the first one to report this, but having gone through the newsgroup, it appears that way. I would like to open a solution in the VS.NET IDE that consists of multiple DLLs and a test application (an .EXE). The .EXE is my startup application. All the DLLs are shared components. This means that they contain a key and are stored in the GAC. When I go to run the test application in the IDE, it will not execute...
9
2771
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and wizards. But, I have found that trying to do something "outside the norm" adds a rather large level of complexity and/or data replication. Background I have been commissioned to create a web-based application for a client. It has a formsaunthentication...
10
1592
by: Steven Spits | last post by:
Hi, Because we have a large WebApp, back in 2002 we decided to use the following method: http://support.microsoft.com/default.aspx?scid=kb;en-us;307467 In short: Create a project "a" at http//localhost/MyWebApp
5
3636
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As String sPPTOut = MDEPDirStr + sID + ".ppt" Dim p As New System.Diagnostics.Process 'p.Start(MDEPDirStr & "macrun.exe", sPPTOut) p.Start("C:\WINDOWS\SYSTEM32\CALC.EXE") 'p.Start("C:\WINDOWS\SYSTEM32\macrun.exe", sPPTOut)
1
6504
by: ritesh.noronha | last post by:
Hi Group, I have a question regarding the commandline options of msbuild. I am currently using msbuild to build projects using the existing solution files. These solution files have references to external dll which have different paths on each machine. I am currently writing a build script and passing the specific path to the project file via the /p: switch of msbuild. My current build line is:
8
2188
by: subramanian100in | last post by:
Suppose I have #include <stdio.h> #include <string.h> size_t strlen(const char *str) { printf("from strlen - %s\n", str); return 0; // return some dummy value
0
8774
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
9307
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
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
9181
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.