471,610 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Transforming with a variable document

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.xs ltMDXtoHTMLAdvanced.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.Creat eNavigator(), 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
Nov 12 '05 #1
4 1896
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.Creat eNavigator(), xslArg,
writer, null);
to
xslt.Transform(xmlSimplified.DocumentElement.Creat eNavigator(), xslArg,
writer, new XmlUrlResolver());

-Naraen

----
"Cathie" <so*****@miscrosoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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.xs ltMDXtoHTMLAdvanced.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.Creat eNavigator(), 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

Nov 12 '05 #2
Thanks for your response. It still doesn't work. Any other ideas?

Cathie
"NaraendiraKumar R. R." <na********@nospam.com> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl...
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.Creat eNavigator(), xslArg,
writer, null);
to
xslt.Transform(xmlSimplified.DocumentElement.Creat eNavigator(), xslArg,
writer, new XmlUrlResolver());

-Naraen

----
"Cathie" <so*****@miscrosoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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.xs ltMDXtoHTMLAdvanced.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.Creat eNavigator(), 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


Nov 12 '05 #3
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
---
"Cathie" <so*****@miscrosoft.com> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
Thanks for your response. It still doesn't work. Any other ideas?

Cathie
"NaraendiraKumar R. R." <na********@nospam.com> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl...
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.Creat eNavigator(), xslArg,
writer, null);
to
xslt.Transform(xmlSimplified.DocumentElement.Creat eNavigator(), xslArg,
writer, new XmlUrlResolver());

-Naraen

----
"Cathie" <so*****@miscrosoft.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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.xs ltMDXtoHTMLAdvanced.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.Creat eNavigator(), 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



Nov 12 '05 #4
Cathie wrote:
xslArg.AddParam("varAdvanced", "", "document('" + advancedOptionsFile +
"')");


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]
http://blog.tkachenko.com
Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mirjana Rakuljic | last post: by
5 posts views Thread by Gustaf | last post: by
1 post views Thread by MaggotChild | last post: by
1 post views Thread by scmorgan | last post: by
reply views Thread by MichaelMortimer | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.