Groups | Blog | Home
all groups > dotnet xml > april 2004 >

dotnet xml : Transforming with a variable document


NaraendiraKumar R. R.
4/6/2004 9:54:55 AM
You are attempting to use an external document in an XSLT. It is a security
issue.

Try changing this line of code
xslt.Transform(xmlSimplified.DocumentElement.CreateNavigator(), xslArg,
writer, null);
to
xslt.Transform(xmlSimplified.DocumentElement.CreateNavigator(), xslArg,
writer, new XmlUrlResolver());

-Naraen

----
[quoted text, click to view]

Cathie
4/6/2004 6:26:43 PM
Hi All,

I am trying to get my style sheet to work. It works fine in IE but I can't
get it to work in .net.

Below is the function I use for transforming, where advancedOptionsFile is
the path to the file containing an XML document required by the
transformation, and xmlSimplified is the XML document to trasform.
----------------------------------------------------------------------------
-------------------------------

string strHTML = String.Empty;

XmlNamespaceManager nsmgr = XmlaWrapper.ReturnXmlaNameSpaceManager();

// Retrieve the XSLT to transform

XmlDocument xsltHTML = new XmlDocument();

xsltHTML.LoadXml(Utilities.GetResource("ZapOLAP.xsltMDXtoHTMLAdvanced.xslt")
);

XslTransform xslt = new XslTransform();

xslt.Load(xsltHTML.DocumentElement.CreateNavigator(), null, null);

// Add the Advanced Formatting XML document as a parameter

XsltArgumentList xslArg = new XsltArgumentList();

xslArg.AddParam("varAdvanced", "", "document('" + advancedOptionsFile +
"')");

using(StringWriter writer = new StringWriter())

{

xslt.Transform(xmlSimplified.DocumentElement.CreateNavigator(), xslArg,
writer, null);

strHTML = writer.ToString();

}

return strHTML;

----------------------------------------------------------------------------
-------------------------------

If I extract the XSLT and XML (adding a xsl statement to the top of the XML
file) and open my xml file in IE, the results occur as they should, but not
when transforming using the above method. The information from the
advancedOptions file seems to be ignored.

Any ideas in what I am doing wrong?

Thanks in Advance

Cathie

NaraendiraKumar R. R.
4/6/2004 11:25:24 PM
Hmmm ...
a ) This line does'nt have any resolver or evidence either.
xslt.Load(xsltHTML.DocumentElement.CreateNavigator(), null, null);

Try change it to
xslt.Load(xsltHTML.DocumentElement.CreateNavigator(), new XmlUrlResolver(),
this.GetType().Assembly.Evidence);

Suggest you read up on the Evidence section of the load method to decide
which evidence method is right for your application.

b) I'm curious about your XSLT. I don't think passing document() as a
parameter value will yield what you are looking for. The only way I have
been successful, is to pass only the filename as the parameter. Then in
the XSLT you can pass the paramter variable to the document function, to
yeild a node-set.

E.g.
Changing the AddParam line to below ...
xslArg.AddParam("varAdvanced", "", advancedOptionsFile);

In the XSLT doing ...
....
<xsl:param name="varAdvanced"/>

<xsl:apply-templates match="/">
<xsl:for-each select="document($varAdvanced)">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:apply-templates>
....

If you success in passing parameter any other way, please share it with the
group. I will be interested in learning from your experience.

Hope this helps,
-Naraen


---
[quoted text, click to view]

Cathie
4/7/2004 9:33:10 AM
Thanks for your response. It still doesn't work. Any other ideas?

Cathie


[quoted text, click to view]

Oleg Tkachenko [MVP]
4/13/2004 10:27:32 AM
[quoted text, click to view]

That won't work. You are effectively passing string, containing
"document()". Just a string. To pass another document to XSLT, load it
into XPathDocument and pass root node as XPathNodIterator.

--
Oleg Tkachenko [XML MVP, XmlInsider]
AddThis Social Bookmark Button