将 XSLT 1.0 转换为 2.0 [英] Convert XSLT 1.0 to 2.0

查看:24
本文介绍了将 XSLT 1.0 转换为 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助将 XSLT 1.0 文件转换为 2.0(以便我可以使用 XSLT 2.0 replace() 函数调用).

我用谷歌搜索过,搜索过不同的书,但没有成功.我尝试将 version="1.0" 更改为 2.0 并更改 html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" 到简单的 html 但这只会导致 XSLTProcessor 错误.

非常感谢任何帮助.提前致谢.

这是我的 XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0"><xsl:output method="xml" omit-xml-declaration="yes" indent="no"doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" encoding="ISO-8859-1"/><xsl:template match="/"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><头><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/><xsl:element name="meta"><xsl:attribute name="name">描述</xsl:attribute><xsl:attribute name="content"><xsl:value-of select="EventList/title"/></xsl:attribute></xsl:element><xsl:element name="link"><xsl:attribute name="rel">alternate</xsl:attribute><xsl:attribute name="type">application/rss+xml</xsl:attribute><xsl:attribute name="title">RSS</xsl:attribute><xsl:attribute name="href"><xsl:value-of select="EventList/rssURL"/></xsl:attribute></xsl:element><身体><xsl:apply-templates select="EventList"/></html></xsl:模板><xsl:template match="EventList"><xsl:when test="事件"><xsl:apply-templates select="Event"/></xsl:when><xsl:否则><div class="eventItem"><div class="eventItemText"><p>目前没有发布此类别的活动.</p>

</xsl:否则></xsl:选择></xsl:模板><!-- 列表--><xsl:template match="事件"><li><!-- 标题--><xsl:if test="eventStatus = 2"><xsl:value-of select="eventStatusString"/>- </xsl:if><xsl:element name="a"><xsl:attribute name="href">http://events.stanford.edu/e/e/?d=<xsl:value-of select="replace(detailpath,'/events/','')"/></xsl:attribute><xsl:attribute name="id"><xsl:value-of select="eventID"/></xsl:attribute><xsl:attribute name="rel">external</xsl:attribute><xsl:value-of select="title" disable-output-escaping="yes"/></xsl:element><!-- 日期和时间--><xsl:element name="a"><xsl:attribute name="href">http://events.stanford.edu/e/details.php?detailpath=<xsl:value-of select="详细路径"/></xsl:attribute><xsl:attribute name="rel">external</xsl:attribute><xsl:when test="repeatRuleID &gt; 0">正在进行中的 <xsl:value-of select="repeatRuleText"/>来自 <xsl:value-of select="beginDate"/>通过 .<xsl:if test="repeatRuleID=99">查看确切日期和时间的详细信息.</xsl:if></xsl:when><xsl:否则><xsl:if test="string(beginDay)"><xsl:value-of select="beginDay"/>, </xsl:if><xsl:value-of select="beginDate"/>.</xsl:否则></xsl:选择><xsl:if test="repeatRuleID!=99"><xsl:if test="string(beginTime)"><xsl:text disable-output-escaping="yes"></xsl:text><xsl:value-of select="beginTime"/>.</xsl:if></xsl:if></xsl:element><!-- 位置--><xsl:element name="a"><xsl:attribute name="href">http://events.stanford.edu/e/details.php?detailpath=<xsl:value-of select="详细路径"/></xsl:attribute><xsl:attribute name="rel">external</xsl:attribute><xsl:value-of select="locationText"/></xsl:element></xsl:模板></xsl:stylesheet>

解决方案

除了将 version 属性改为 '2.0' 之外,还需要提要您的 XSLT 2.0 代码到 XSLT 2.0 处理器.

目前我使用的一些 XSLT 2.0 处理器有:

请注意,现有的 XSLT 1.0 代码在 XSLT 2.0 下的行为可能有所不同——最明显的区别是 不再产生节点集中仅第一个节点的字符串值,而在 XSLT 2.0 中,可怕的 RTF 类型已被消除,因此不需要/提供 xxx:node-set() 扩展函数.

I need help converting an XSLT 1.0 file to 2.0 (so I can use the XSLT 2.0 replace() function call).

I've Googled, searched different books and SO with no success. I tried changing version="1.0" to 2.0 and changing html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" to simply html but this all just results in XSLTProcessor errors.

Any help is greatly appreciated. Thanks in advance.

Here is my XSLT:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="xml" omit-xml-declaration="yes" indent="no"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" encoding="ISO-8859-1" /> 
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<xsl:element name="meta">
<xsl:attribute name="name">description</xsl:attribute>
<xsl:attribute name="content"><xsl:value-of select="EventList/title"/></xsl:attribute>
</xsl:element>
<xsl:element name="link"><xsl:attribute name="rel">alternate</xsl:attribute><xsl:attribute name="type">application/rss+xml</xsl:attribute><xsl:attribute name="title">RSS</xsl:attribute><xsl:attribute name="href"><xsl:value-of select="EventList/rssURL"/></xsl:attribute></xsl:element>
</head>
<body>
 <xsl:apply-templates select="EventList" />
</body>
</html>
</xsl:template>
<xsl:template match="EventList">
 <xsl:choose>
  <xsl:when test="Event">
   <xsl:apply-templates select="Event"/>
  </xsl:when>
  <xsl:otherwise>
   <div class="eventItem">
    <div class="eventItemText">
     <p>There are currently no events posted for this category.</p>
    </div>
   </div>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>
<!-- List -->
<xsl:template match="Event">
 <li>
  <!-- Title -->
  <xsl:if test="eventStatus = 2"><xsl:value-of select="eventStatusString"/> - </xsl:if>
  <xsl:element name="a"><xsl:attribute name="href">http://events.stanford.edu/e/e/?d=<xsl:value-of select="replace(detailpath,'/events/','')"/></xsl:attribute><xsl:attribute name="id"><xsl:value-of select="eventID"/></xsl:attribute><xsl:attribute name="rel">external</xsl:attribute>
   <xsl:value-of select="title" disable-output-escaping="yes"/>
  </xsl:element>
  <!-- Date and time -->
  <xsl:element name="a"><xsl:attribute name="href">http://events.stanford.edu/e/details.php?detailpath=<xsl:value-of select="detailpath"/></xsl:attribute><xsl:attribute name="rel">external</xsl:attribute>
   <xsl:choose>
    <xsl:when test="repeatRuleID &gt; 0">
     Ongoing <xsl:value-of select="repeatRuleText"/> from <xsl:value-of select="beginDate"/> through <xsl:value-of select="repeatUntilDate"/>.
     <xsl:if test="repeatRuleID=99">See details for exact dates and times.</xsl:if>
    </xsl:when>
    <xsl:otherwise>
     <xsl:if test="string(beginDay)"><xsl:value-of select="beginDay"/>, </xsl:if>
     <xsl:value-of select="beginDate"/>.
    </xsl:otherwise>
   </xsl:choose>
   <xsl:if test="repeatRuleID!=99">
    <xsl:if test="string(beginTime)">
     <xsl:text disable-output-escaping="yes"></xsl:text><xsl:value-of select="beginTime"/>.
    </xsl:if>
   </xsl:if>
  </xsl:element>
  <!-- Location -->
  <xsl:element name="a"><xsl:attribute name="href">http://events.stanford.edu/e/details.php?detailpath=<xsl:value-of select="detailpath"/></xsl:attribute><xsl:attribute name="rel">external</xsl:attribute>
   <xsl:value-of select="locationText"/>
  </xsl:element>
 </li>
</xsl:template>
</xsl:stylesheet>

解决方案

In addition to changing the version attribute to '2.0', you need to feed your XSLT 2.0 code to an XSLT 2.0 processor.

At present, some of the XSLT 2.0 processors I use are:

Do note that an existing XSLT 1.0 code may behave differently under XSLT 2.0 -- the most obvious differences are that <xsl:value-of> no longer produces the string value of only the first node from a node-set, and that in XSLT 2.0 the dreaded RTF type has been eliminated, so no xxx:node-set() extension function is needed/provided.

这篇关于将 XSLT 1.0 转换为 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆