XSLT Param范围? [英] XSLT Param Scope?

查看:101
本文介绍了XSLT Param范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当庞大的XSLT文件,为了调试和清晰起见,我希望将b $ b分成一些单独的子模板,这些子模板包含在同一个

文件中。主模板调用apply-templates并将节点集传递给

。该模板反过来定义了大约15个变量,这些变量决定了以下模板应该如何进行。伪示例:


<! - 通过.NET XSLTransform()调用的根转换 - >

< xsl:template match =" /">

..做一堆东西来渲染html

< xsl:apply-template select =" // object [@class = ''lineItem''和

@ffid =''费用'']" mode =" LINEITEM" />

......更多的html内容

< / xsl:template>


< xsl:template select =" // object" mode =" LINEITEM">

<! - 根据当前节点定义一堆变量,这些变量规定了html中该节点的详细格式 -
- >


<! - 选择1 --->

做一些格式化

<! - - 或 - >

<! - choice 2 --->

做一些其他格式化

< / xsl :模板>


现在我想做的是将选择1和选择2移到他们自己的

模板中,而不必重新定义所有'' '格式''变量。我知道在样式表级别定义的param在任何

子模板中都可用,但是,如果在模板中使用
,它看起来很自然
call-template或apply-template意味着父母的参数是

可用,nes-pas?就像在旧的VB 6天中你将有一个公共的

变量应用程序和一个私有变量定义在

类的声明中,换句话说,public to这个类但不是

应用程序。这是可能还是我的头被困在对象土地上远远多了

多:-)


干杯

Keith

PS:如果不可能那应该是因为它对我来说似乎是完全符合逻辑的,

有人写了一个扩展! :-)

解决方案

>现在我想要做的是将选择1和选择2移动到他们自己的

模板中,而不必重新定义所有''格式''变量。我意识到在样式表级别定义的param在任何
子模板中都可用,但是,如果在使用
a call-template或apply-template的模板中,这看起来很自然父母的上下文是否可用,nes-pas?




没有什么是可用的通过它自己。模板

中的参数/变量将作为

参数传递给被调用(或应用)模板。


了解xsl:with-param和xsl:param指令。


=====

干杯,


Dimitre Novatchev。
http://fxsl.sourceforge。 net / - FXSL的主页


我知道这将是你的答案,仍然是同样的问题,但是两倍。

现在我在父模板中定义它们,在我调用的每个

模板的with-param中。


我意识到如何它起作用,我说的是这个语言在这个领域缺乏优雅。能够说:


< xsl:param name =" myvar"范围= QUOT; [模板] [样式表]" value ="" />


在模板外定义的param会自动拥有

模板的范围,但在模板中你可以覆盖它和州样式表

从而使可用到样式表中的任何模板。我可以认为

的很多实现,如果有一个文档片段很好,那么基于模板处理将
放在参数中然后可用

转换中的任何其他模板。


干杯

基思


Dimitre Novatchev ; < DN ******** @ yahoo.com>在消息中写道

news:bq ************* @ ID-152440.news.uni-berlin.de ...

现在我想做的是将选择1和选择2移到他们自己的
模板中,而不必重新定义所有''格式''变量。我知道在样式表级别定义的param在任何
子模板中都可用,但是,如果在模板


中使用

call-template或apply-template意味着父母参数可用,nes-pas?



没有什么是可用的通过它自己。如果将它们作为
参数传递,模板中的参数/变量将可用于被调用(或应用)的模板。

了解xsl:with-param和xsl:param对说明。

=====
干杯,

Dimitre Novatchev。
http://fxsl.sourceforge.net/ - FXSL的主页





" Keith Chadwick" < KC ******* @ leewardsystems.com>在消息中写道

news:uB ************** @ tk2msftngp13.phx.gbl ...

我知道那将是你的答案仍然是同样的问题,但两倍于
多。现在我在父模板中定义它们,在我调用的每个
模板的with-param中。

我意识到它是如何工作的,我说的是语言缺乏
< xsl:param name =" myvar"范围= QUOT; [模板] [样式表]" value ="" />

在模板外定义的param会自动具有
模板的范围,但在模板中你可以覆盖它和状态样式表
从而使可用到样式表中的任何模板。我可以想到很多实现,如果根据模板处理将文档
片段放在param中,然后将
用于转换中的任何其他模板,那将是很好的。




如果没有上面提出的结构,这是完全可能的:


< xsl:variable name =" vrtfVar">

< xsl:apply-templates />

< / xsl:variable>


< ; xsl:apply-templates select =" someExpression">

< xsl:with-param name =" somepName"选择= QUOT; msxsl:节点集(


I have a fairly hefty XSLT file that for the sake of debugging and clarity I
wish to split into some separate sub-templates contained within the same
file. The master template calls an apply-templates and passes a node set to
it. This template in turn defines approximately 15 variables that dictate
how the following template should proceed. Pseudo example:

<!-- Root transformation called via .NET XSLTransform()-->
<xsl:template match="/">
.. do a bunch of stuff to render the html
<xsl:apply-template select="//object[@class=''lineItem'' and
@ffid=''fees'']" mode="LINEITEM"/>
...bunch more of html stuff
</xsl:template>

<xsl:template select="//object" mode="LINEITEM">
<!-- define a bunch of variables based on the current node that dictate
the detailed formatting of that node in html -->

<!-- choice 1 --->
do some formatting
<!-- or -->
<!-- choice 2 --->
do some other formatting
</xsl:template>

Now what I would like to do is move choice 1 and choice 2 into their own
templates and NOT have to redefine all of the ''formatting'' variables. I
realize that a param defined at the stylesheet level is available in any
child template but, and it would seem natural, if within a template using a
call-template or apply-template would mean that the parents params are
available, nes-pas? Like in the old VB 6 days where you would have a public
variable to the application and a private variable defined in the
declarations of class, in other words, public to the class but not the
application. Is this possible or is my head stuck in object land far to
much :-)

Cheers
Keith

PS: If not possible it should be because it seems completely logical to me,
somebody write an extension!!! :-)


解决方案

> Now what I would like to do is move choice 1 and choice 2 into their own

templates and NOT have to redefine all of the ''formatting'' variables. I
realize that a param defined at the stylesheet level is available in any
child template but, and it would seem natural, if within a template using a call-template or apply-template would mean that the parents params are
available, nes-pas?



Nothing is "available" by itself. The parameters/variables in a template
will be available to a called (or applied) template if you pass them as
parameters.

Read about the xsl:with-param and xsl:param pair of instructions.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


I knew that would be your answer and still the same issue but twice as much.
Now I am defining them in the parent template, in the with-param for each
template I call.

I realize how it works and what I am stating is that the language lacks
elegance in this area. It would be nice to be able to say:

<xsl:param name="myvar" scope="[template][stylesheet]" value=""/>

A param defined outside of a template would automatically have a scope of
template but inside a template you could override it and state stylesheet
thereby making "available" to any template in the style sheet. I can think
of a lot implementations where it would be nice to have a document fragment
placed in the param based on the templates processing and then be available
to any other template in the transformation.

Cheers
Keith

"Dimitre Novatchev" <dn********@yahoo.com> wrote in message
news:bq*************@ID-152440.news.uni-berlin.de...

Now what I would like to do is move choice 1 and choice 2 into their own
templates and NOT have to redefine all of the ''formatting'' variables. I
realize that a param defined at the stylesheet level is available in any
child template but, and it would seem natural, if within a template

using a

call-template or apply-template would mean that the parents params are
available, nes-pas?



Nothing is "available" by itself. The parameters/variables in a template
will be available to a called (or applied) template if you pass them as
parameters.

Read about the xsl:with-param and xsl:param pair of instructions.

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL




"Keith Chadwick" <kc*******@leewardsystems.com> wrote in message
news:uB**************@tk2msftngp13.phx.gbl...

I knew that would be your answer and still the same issue but twice as much. Now I am defining them in the parent template, in the with-param for each
template I call.

I realize how it works and what I am stating is that the language lacks
elegance in this area. It would be nice to be able to say:

<xsl:param name="myvar" scope="[template][stylesheet]" value=""/>

A param defined outside of a template would automatically have a scope of
template but inside a template you could override it and state stylesheet
thereby making "available" to any template in the style sheet. I can think of a lot implementations where it would be nice to have a document fragment placed in the param based on the templates processing and then be available to any other template in the transformation.



This is perfectly possible to do without the constructs you propose above:

<xsl:variable name="vrtfVar">
<xsl:apply-templates/>
</xsl:variable>

<xsl:apply-templates select="someExpression">
<xsl:with-param name="somepName" select="msxsl:node-set(


这篇关于XSLT Param范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆