使用应用的样式表参数导入XSLT样式表

使用应用的样式表参数导入XSLT样式表,xslt,xslt-2.0,Xslt,Xslt 2.0,如何导入样式表,应用实际的参数值 到所谓的样式表?这是一个例子 假设我有一个通用样式表,它接受一个参数“x”。 它看起来像这样,位于“general.xslt” 输出: Transform.exe -s:specific.xslt -xsl:specific.xslt -o:specific-out.xml y=abc <?xml version="1.0" encoding="UTF-8"?><root>The value of x is abc!</roo

如何导入样式表,应用实际的参数值 到所谓的样式表?这是一个例子

假设我有一个通用样式表,它接受一个参数“x”。 它看起来像这样,位于“general.xslt”

输出:

 Transform.exe -s:specific.xslt -xsl:specific.xslt -o:specific-out.xml y=abc
 <?xml version="1.0" encoding="UTF-8"?><root>The value of x is abc!</root>
x的值是abc!

general.xslt的实际参数是“abc!”

您可以使用xsl:param或xsl:variable(显示在顶层,即导入模块中xsl:stylesheet的子级)覆盖xsl:param



对不起,尽管我尽力想理解这里的问题,但我还是做不到。样式表不被调用——这让人困惑。你真正想要实现什么?请您编辑这个问题使其更有意义好吗?是的,您是对的,样式表是导入或包含的,而不是调用的。问题已相应更新。在编译过程中的某个时刻,导入的样式表的形式参数需要绑定到某些特定的实际值。问题的重点是如何在调用样式表中绑定该值。Michael的答案是在调用样式表中定义一个同名的参数或变量。我对此感到惊讶。来自过程背景,我期望在调用命名模板或函数时使用类似的参数绑定机制。导入样式表模块中的任何全局变量在任何导入(直接或间接)样式表中都是可见的,并覆盖这些样式表模块中任何同名的变量。这是因为
xsl:import
语句始终必须位于任何其他全局级语句之前。所以aglobal
xsl:variable总是在任何
xsl:import`之后,并且具有更高的优先级。谢谢。顺便说一句,我买了你的书。我会把它推荐给任何人。其中最精彩的部分是《骑士之旅》一章——那真是令人愉快。
 <xsl:stylesheet 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns:fn="http://www.w3.org/2005/xpath-functions"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   version="2.0"
   exclude-result-prefixes="xsl xs fn">
 <xsl:param name="x" as="xs:string" />
 <xsl:template match="/">
  <root>
   The value of x is <xsl:value-of select="$x" />
  </root>
 </xsl:template>
 </xsl:stylesheet>
<xsl:stylesheet 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns:fn="http://www.w3.org/2005/xpath-functions"
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:my="http://my.com"
   version="2.0"
   exclude-result-prefixes="xsl xs fn my">
 <xsl:import href="general.xslt" />
 <xsl:param name="y" as="xs:string" />

 <xsl:function name="my:some-function" as="xs:string">
   <xsl:param name="value" as="xs:string" />
   <xsl:value-of select="concat( $value, '!') " />
 </xsl:function>
 <xsl:variable name="x" select="my:some-function($y)" />

 <xsl:template match="/">
  <xsl:apply-imports/>
 </xsl:template>
</xsl:stylesheet>
 Transform.exe -s:specific.xslt -xsl:specific.xslt -o:specific-out.xml y=abc
 <?xml version="1.0" encoding="UTF-8"?><root>The value of x is abc!</root>
<xsl:variable name="x" select="some-function($y)" />