0

ある組織 (例: www.old.com) が所有していたサイトを管理しており、現在は新しい組織 (例: www.new.com) に置き換えられています。私の問題は、サイトで使用している一部の画像の一部のリンクがまだ古い組織を指していることです. xsl を使用してhttp://www.old.comhttp://www.new.comに置き換える方法があるかどうか疑問に思っていました。

私の考えはこれをやっていましたが、うまくいくかどうかはわかりません..

 <xsl:template match="image">
<xsl:param name ="old" value='http://www.old.com'/>
 <xsl:param name ="new" value='http://www.new.com'/>
  <xsl:choose>
          <xsl:when test="contains(@xlink:href,$old)">
            <xsl:attribute name="xlink:href">
              <xsl:value-of select="replace(@xlink:href, $old, $new)">
            </xsl:attribute>
          </xsl:when>
          <xsl:otherwise>
            <xsl:attribute name="xlink:href">
              <xsl:value-of select="@xlink:href"/>
            </xsl:attribute>
          </xsl:otherwise>
        </xsl:choose>
</xsl:template>

xml は次のようになります。

<book title="Harry Potter">
 <description
 xlink:type="simple"
  xlink:href="http://www.old.com/images/HPotter.gif"
  xlink:show="new">
 As his fifth year at Hogwarts School of Witchcraft and
 Wizardry approaches, 15-year-old Harry Potter is.......
  </description>
</book>

ご協力いただきありがとうございます

4

1 に答える 1

1

がすべてのノードをトラバースすると仮定するとapply-templates(以下の最初のテンプレートを参照)、以下が機能するはずです。

<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="@xlink:href">
  <xsl:param name ="old">http://www.old.com</xsl:param>
  <xsl:param name ="new">http://www.new.com</xsl:param>
  <xsl:attribute name="xlink:href">
    <xsl:value-of select="replace(., $old, $new)"/>
  </xsl:attribute>
</xsl:template>
于 2012-12-30T15:40:45.923 に答える