views:

49

answers:

2

Is there a way to retrieve the media-type value? e.g. like OutputSettings.OutputMethod used to get xsl:output method.

A: 

You could query the XSL stylesheet via your preferred method of handling XML (for example as an XmlDocument) and issue the following XPath query (don't forget to make the xsl namespace available to XPath beforehand with a NamespaceManager):

/*/xsl:output/@media-type

The equivalent could be also achieved with LINQ.

Tomalak
Thanks Tomalak. It works. I never thought XSLT is similar structure as XML. Cool.
HH
@HH: XSLT ist not a "similar structure", XSLT *is* XML - simple as that. ;)
Tomalak
+1  A: 
XPathNavigator objArgXPathNavigator = objArgXsltDocument.CreateNavigator();
XPathExpression objXPathExpression = objArgXPathNavigator.Compile("/*/xsl:output/@media-type");
XmlNamespaceManager objXmlNamespaceManager = new XmlNamespaceManager(objArgXPathNavigator.NameTable);
objXmlNamespaceManager.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
objXPathExpression.SetContext(objXmlNamespaceManager);

XPathNodeIterator nodes = objArgXPathNavigator.Select(objXPathExpression);
while (nodes.MoveNext())
{
  objArgHttpContext.Response.Write(nodes.Current.ToString());
}
HH
+1 for sharing the code. Certainly one way to do it.
Tomalak