简体   繁体   English

覆盖XSL调用模板

[英]overriding XSL call-template

I have an XSL stylesheet that I need to use because it has stuff that's really hard to recreate. 我有一个XSL样式表,我需要使用它,因为它确实很难重建。 And I can't edit it, either. 而且我也无法编辑。 So I'm using <xsl:import> to import the XSL stylesheet, and then I'm overriding a few templates. 因此,我使用<xsl:import>导入XSL样式表,然后覆盖了一些模板。 But one has me stumped: 但是我难过了:

<xsl:template match="mscript">
<html>
   <!-- head -->
   <head>

      <!-- ... other stuff not important ... -->

      <xsl:call-template name="stylesheet"/>
   </head>
   <body>
      <!-- ... more stuff ... -->

and the stylesheet template, which sticks in a <style type='text/css'>...</style> tag and is mostly useful, starts with this boneheaded nonsense: 粘贴在<style type='text/css'>...</style>标记中且最有用的stylesheet模板从这个笨拙的废话开始:

<xsl:template name="stylesheet">
  <style type="text/css">
     html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,
     a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,
     small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,
     form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td
     {margin:0;padding:0;border:0;outline:0;font-size:100%;
      vertical-align:baseline;background:transparent}    

Argh! 哎呀! Makes me nauseous. 使我恶心。

I can override the stylesheet completely in my root XSL file, but what I'd really like to do is just nullify this one CSS rule. 我可以在XSL根文件中完全覆盖样式表,但是我真正想做的只是使这条CSS规则无效。

Is there a way to do that? 有没有办法做到这一点? Here's kind of what I'd like to do: 这是我想做的事情:

<xsl:template name="stylesheet">
   <xsl:call-template name="imported_stylesheet" />
   <style type="text/css">
      <!-- nullify the boneheaded nonsense -->
     h1,h2,h3,h4,h5,h6,p,blockquote,pre,
     a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,
     small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,
     form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td
     {margin: default; padding:default;border:default;outline:default;font-size:default;
      vertical-align:default;background:default}    
   </style>
 </xsl:template>

but default isn't a CSS feature, and I don't know how to call the imported stylesheet, since when I override the stylesheet template, its previous value disappears. default不是CSS功能,并且我不知道如何调用导入的样式表,因为当我覆盖stylesheet模板时,其先前的值会消失。

I believe CSS does not currently have a way to reset a style to the browser default value (See Reset CSS display property to default value ) 我认为CSS当前没有将样式重置为浏览器默认值的方法(请参阅将CSS显示属性重置为默认值

I can think of one very 'crude' way of doing what you are trying to achieve. 我可以想到一种非常“粗糙”的方式来完成您要达到的目标。 Assuming the stylesheet template does just return a single style element, you could wrap the call:template command in a variable, and then just strip out the first rule. 假设样式表模板只返回一个样式元素,则可以将call:template命令包装在一个变量中,然后删除第一个规则。 Something like this 像这样

<xsl:variable name="style">
   <xsl:call-template name="stylesheet"/>
</xsl:variable>
<style type="text/css">
   <xsl:value-of select="substring-after($style, '}')" />
</style>

This would just out the CSS rules after the first one. 这只是第一个规则之后的CSS规则。

Are you sure you cannot edit the imported stylesheet though? 您确定不能编辑导入的样式表吗? Can't you hunt down the person who wrote it, and ask them to change it to allow a parameter which specifies whether you want the first rule or not? 您是否无法追查编写它的人,并要求他们更改它以允许使用指定您是否要第一个规则的参数? Or maybe you can just take a copy of the imported stylesheet, and change it for you own purpose.... 或者,您可以只是复制导入的样式表,并根据自己的需要进行更改。...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM