473,231 Members | 1,929 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,231 software developers and data experts.

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 2455
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!PLEASEtkachenko.com> wrote in message
news:eG**************@TK2MSFTNGP12.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(Console.Out);
writer.Formatting=Formatting.Indented;
or
XmlTextWriter xtwDump = new
XmlTextWriter("C:\\dumpXslTest.xml",System.Text.En coding.UTF8);
xtwDump.Formatting = Formatting.Indented;

in the web environment, to generate the data island use something like
strmOutput = new
StreamWriter(HttpContext.Current.Response.OutputSt ream,System.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 prvTransformDataset()
{
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\\gene ral.xslt"; //Point A
below

try
{
//Get the raw XML data
SqlXmlCommand cmd = new SqlXmlCommand(strConn);
cmd.RootTag = "XML";
cmd.CommandText = "Select * from tablename for xml auto";
cmd.CommandType = SqlXmlCommandType.Sql;
XmlReader xReader = cmd.ExecuteXmlReader();

//Load into a suitable document
XPathDocument xpathdocument = new
XPathDocument(xReader,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="document('C:/projects/projectfolder/BusinessObject/tableschema.xml')
" />
XmlUrlResolver xrsSchema = new XmlUrlResolver();
Uri uriSchema = new Uri(stylesheet);
Uri uriFull = xrsSchema.ResolveUri(uriSchema,"tableschema.xml");
xslt.Load(stylesheet); //Point B below

//Create an XsltArgumentList to pass in the parameterised tags
// A bindable data island has three levels
XsltArgumentList xslArg = new XsltArgumentList();
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.Flush();
return(true);
}
catch(Exception e)
{
XmlTextWriter txwError = new XmlTextWriter(Console.Error);
txwError.WriteRaw(("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:transform 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="'islandId'"/>
<xsl:param name="Group" select="'collection'"/>
<xsl:param name="Line" select="'data'"/>
<xsl:variable name="Sch"
select="document('C:/projects/projectfolder/BusinessObject/tablename.xml')"
/>

<!--Match the root node -->
<xsl:template match="/">
<xsl:element name="xml">
<xsl:attribute 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_location']/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:attribute name='{$fieldname}'>
<!-- xsl:value-of select='$row/@*[name()=$fieldname]'/ -->
<xsl:variable name="datevalue" select='$row/@*[name()=$fieldname]'/>
<xsl:if test="$datevalue!=''">
<xsl:value-of select="substring($datevalue,9,2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring($datevalue,6,2)"/>
<xsl:text>/</xsl:text>
<xsl:value-of select="substring($datevalue,1,4)"/>
<xsl:text> </xsl:text>
<xsl:value-of

select="substring(substring-after($datevalue,'T'),1,8)"/>
</xsl:if>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<!-- 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:attribute name='{$fieldname}'>
<xsl:value-of select='$row/@*[name()=$fieldname]'/>
</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"
elementFormDefault="qualified">
<xs:element name="SGC">
<xs:complexType>
<xs:sequence>
<xs:element ref="lps_location" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="lps_location">
<xs:complexType>
<xs:attribute name="LOCATION_ID" type="xs:short" use="required"/>
<xs:attribute name="INITIAL_LOCATION_ID" type="xs:short" use="required"/>
<xs:attribute name="PREDECESSOR_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_BY" type="xs:string" use="required"/>
<xs:attribute name="CREATED_DATE" type="xs:dateTime" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
Point B.

I couldn't get any joy from using the overloaded "Load" method
(stylesheet,resolver).
Perhaps this is used to resolve the "xsl:import" and "xsl:include"
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.xml".
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.microsoft.com> wrote in message
news:ms**************@cpmsftngxa06.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/cpconresolvingexternalxsltstylesheetsdocuments.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
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...
4
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...
1
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...
2
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...
9
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...
10
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...
5
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...
1
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...
8
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
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.