条件 <xsl:output>在 XSLT 1.0 中? [英] Condition <xsl:output> in XSLT 1.0?

查看:20
本文介绍了条件 <xsl:output>在 XSLT 1.0 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 XSLT 1.0(2.0 不是一个选项)样式表,它产生XHTML.它可以根据参数生成完整的 XHTML有效的文档或只是一个

...

片段,用于包含在网页中.

我的问题是在这两个中产生不同的 XML 声明案件.对于独立页面,我需要:

<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

对于

之一:

但是 不能包含在 中.它只能是 直接 子级.

我看到的唯一解决方案是使用大多数模板创建一个样式表,然后使用正确的 <xsl:output> 和两个小的包装器"创建 <xsl:import> 主样式表.

我一直在寻找更好的主意,但显然没有.根据 Andrew Hare 和 jelovirt 的建议,我编写了两个驱动程序",两个简单的样式表,它们分别调用了正确的 和主样式表.这是这些驱动程序之一,用于独立 HTML 的驱动程序:

<xsl:import href="traceroute2html.xsl"/><xsl:param name="standalone" select="'true'"/><xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/></xsl:stylesheet>

解决方案

听起来您需要的是两个不同的样式表.如果可能,您应该创建两个单独的样式表并从代码中动态调用您需要的样式表.

I have an XSLT 1.0 (2.0 is not an option) stylesheet which produces XHTML. It can, depending on a parameter, produce a full XHTML validable document or just a <div>...</div> snippet, intended for inclusion in a Web page.

My problem is to produce different XML declarations in these two cases. For the standalone page, I need:

<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
       doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

And for the <div> one:

<xsl:output omit-xml-declaration="yes"/>

But <xsl:output> cannot be included in an <xsl:if>. It can only be the direct child of <xsl:stylesheet>.

The only solution I see is to create a stylesheet with most of the templates and then two small "wrappers" with the right <xsl:output> and which will <xsl:import> the main stylesheet.

I was looking for a better idea but apparently there is none. Following advice from Andrew Hare and jelovirt, I wrote two "drivers", two simple stylesheets which call the proper <xsl:output> and then the main stylesheet. Here is one of these drivers, the one for standalone HTML:

<?xml version="1.0" encoding="us-ascii"?>
<!-- This file is intended to be used as the main stylesheet, it creates a 
 standalone Web page. 
-->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

  <xsl:import href="traceroute2html.xsl"/>

  <xsl:param name="standalone" select="'true'"/>

  <xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
      doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

</xsl:stylesheet>

解决方案

It sounds like what you need is two different stylesheets. If at all possible you should create two separate stylesheets and dynamically call the one you need from code.

这篇关于条件 &lt;xsl:output&gt;在 XSLT 1.0 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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