473,326 Members | 2,113 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,326 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 2458
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
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.