English 中文(简体)
• 如何写上所有XSL模板,这些模板也穿过所有的碎片?
原标题:How to write a catch all XSL template that also passes all the params?

我正在撰写一个“扩展”模板模板,但有一些问题。

<xsl:template match="*[@condition]" mode="#all">
<xsl:element name="condition">
  <xsl:attribute name="name">
    <xsl:value-of select="@condition"></xsl:value-of>
  </xsl:attribute>
  <xsl:apply-imports>
  </xsl:apply-imports>
</xsl:element>

The problem with this is templates called using <xsl:apply-imports> are missing params. The list of params are not known since there are many different templates that this template is trying to extend (hence the mode="#all").

Is there a good way around this?


其他例子:

考虑两个最后模板(仅限):

<xsl:template match="*" mode="mode1">
    <param name="p1"/>
</xsl:template>

<xsl:template match="*" mode="mode2">
    <param name="p2"/>
</xsl:template>

they are called somewhere (read-only):

<xsl:apply-templates mode="mode1">
    <xsl:with-param name="mode1" select="$mode1"/>
</xsl:apply-templates>

<xsl:apply-templates mode="mode2">
    <xsl:with-param name="mode2" select="$mode2"/>
</xsl:apply-templates>

There might be 100s of mode1, mode2, mode3, mode4 ... and the names do not have a pattern.

我希望有一个全球模板,在最后模板周围收集更多的信息。 类似:

<xsl:template match="*" mode="#all">
    <xsl:next-match/>
</xsl:element>

问题是,上述全球模板没有将斜线传递给模板。

最佳回答

如果您的问题是,当您打电话<xsl:apply-imports>。 这不包括目前模板所用的参数,你可以使用隧道参数。 在模板中,你正在推广你这样的参数:

<xsl:param name="foo" tunnel="yes"/>

此外,在通过参数时:

<xsl:with-param name="foo" tunnel="yes"/>

我也建议使用<代码><xsl:next-match>而不是<xsl:apply-imports>

问题回答

You can either use tunnel parameters as suggested by Max Toro, or you could just pass a single parameter, whose children are the parameters that different templates will need and will recognize.

www.un.org/Depts/DGACM/index_spanish.htm 类似于:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:param name="pComposite" as="element()*">
   <param for="templateX" name="pA">
    12
   </param>
   <param for="templateY" name="pB">
    Some String
   </param>
 </xsl:param>

 <xsl:template match="*[@condition]">
  <condition name="{@condition}">
   <xsl:apply-imports>
     <xsl:with-param name="pComposite"
      select="$pComposite"/>
   </xsl:apply-imports>
  </condition>
 </xsl:template>
</xsl:stylesheet>




相关问题
Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

How to create a submit button template in Oracle APEX?

I m trying to create a template for a button in Oracle APEX but I don t seem to have access to the appropriate substitution strings to make it work. For non-templated buttons APEX seems to insert a ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Load ruby on rails template from database

I wonder if there is a way for me to store ruby on rails view files into database store and have that fetched directly from there. The reason is I want to create a CMS with all the user data stored in ...

Templated HTML Editor

I m looking for a HTML editor that kinda supports templated editing or live snippets or something like that. Background: I m working on a website for a friend. As there are no specifications what the ...

Dreamweaver changing path to site s reference instead of local

I have noticed recently, when I apply a template to a new HTML website, all the relative paths are pointed to my local files, example: file:///C|/webstuff/files but I cannot set them to relative paths ...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...

热门标签