2011-01-21 27 views
3

XSLT 1.0ファイルを2.0に変換する際に助けが必要です(XSLT 2.0のreplace()関数呼び出しを使用できるようになりました)。XSLT 1.0を2.0に変換する

私はグーグルで、さまざまな本を検索したので、成功しませんでした。私はversion="1.0"2.0に変更し、html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"を単にhtmlに変更しようとしましたが、このすべてがXSLTProcessorエラーを引き起こします。

ご協力いただきまして誠にありがとうございます。前もって感謝します。​​にversion属性を変更することに加え

<?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> 
+0

XSLT 2.0をサポートするプロセッサを使用していますか? –

+0

私は確信していません - それはPHP(バージョン5.2.6)で処理されています。 – Ryan

+2

私はPHPがlibxsltを使用しており、XSLT 2.0をサポートしていないと信じています。 –

答えて

3

は、あなたがXSLT 2.0プロセッサにあなたのXSLT 2.0コードを供給する必要があります。

は、ここに私のXSLTです。現在

、私が使用XSLT 2.0プロセッサの一部である:

既存XSLT 1.0のコードがXSLT 2.0の下で異なる挙動を示す可能性があることに注意を実行してください - 最も明白な違いは<xsl:value-of>はもはやノード集合から最初のノードの文字列値を作成し、その中にいることではありません恐ろしいRTFタイプのXSLT 2.0が削除されたため、xxx:node-set()拡張機能は必要とされていません。

1

また、非正規のXSLT 2.0付録J Changes from XSLT 1.0もチェックしてください。

このセクションでその挙動に完全に、XSLT 1.0によって を指定されたXSLT 2.0の下で異なる 結果を生成するXSLT 1.0、 及び下(エラーを生じない) 有効なスタイルシートであった全ての既知の事例 。

1

コードを変換している間、これらの醜いdisable-output-escaping = "yes"属性を取り除く必要があります。彼らはほとんど確かに欲しくない。この属性を使用すると、通常、初心者が言語の理解度が低いと書かれたことを示します。また、これは一般的にはるかに読みやすい

<a href="http://events.stanford.edu/e/e/?d={replace(detailpath,'/events/','')}" 
    id="{@eventID}" rel="external"> 
    <xsl:value-of select="title"/> 
</a> 

置き換えることができる

<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> 

のような冗長な構築物の使用に適用される、いくつかのリファクタリングは、このコードに長年の懸案です。

+0

ご意見ありがとうございます。私はちょうど私のPHPサーバがXSLT 1.0に限定されていることを発見しました。 私はXSLT 1.0 [置き換える機能のためのソリューション] [1](感謝@Alejandro)見つけた: ストリング(detailpath、9 *を開始-で(detailpath、 '/イベント/')) 改訂コードでこの機能を組み込みましたが、さまざまなエラーが発生し続けました。この関数でリンクコードを単純化するにはどうすればよいですか? [1]:http://stackoverflow.com/questions/4754332/regex-to-remove-word-from-xslt – Ryan