开发者

Is it possible to pass XML stream as parameter to XSLT?

I have following problem that in a transformation (which is completely done in memory) should recieve an additional XSLT parameter containing another XML stream. It's开发者_StackOverflow中文版 like merging two XML documents together in memory. Writing it down on the drive and load it dynamically is not a possibility.

To develop I use .Net together with Visual Studio 2010.


Well which programming language, which XSLT processor do you use? What kind of parameters an XSLT processor takes is processor dependent, for instance with .NET's XslCompiledTransform you could certainly define a global parameter in your XSLT code and then use the XsltArgumentList to pass in an IXPathNavigable (i.e. XmlDocument or XPathDocument) created from your stream.


It's possible with .NET (i've tested 4.0). It worked with following code:

C#:

XslCompiledTransform proc = new XslCompiledTransform();
proc.Load(path + "test_parameter.xslt");

System.IO.TextWriter result = new StreamWriter(path + "result.html");

XmlDocument docA = new XmlDocument();
docA.Load(path + "documentA.xml");

XmlDocument docB = new XmlDocument();
docB.Load(path + "documentB.xml");

XsltArgumentList xsltArgs = new XsltArgumentList();
xsltArgs.AddParam("xmlDoc", "", docB);

proc.Transform(docA, xsltArgs, result);

XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <!-- THIS FILE GENERATES A SIMPLE HTML  -->
  <xsl:output method="html" indent="yes"/>
  <xsl:param name="xmlDoc" />    

  <xsl:template match="/document">
     <xsl:apply-templates select="$xmlDoc/foo/bar"/>
  </xsl:template>
</xsl:stylesheet>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜