0

登録せずにこのサイトの長年のユーザー。今、解決するのは簡単だと確信していますが、どの検索でも関連する資料が表示されない問題を見つけました!

私の質問は、このxmlの例で単純化されています:

<root_element>
 <content>
  <content-detail>
    <name>TV Show Name</name>
    <value> Father Ted </value>
  </content-detail>

  <content-detail>
    <name>Airing Status</name>
     <value> Cancelled </value>
  </content-detail>

 </content>
</root_element>

この完全に架空の例で、Father Ted を「Father Ted -- CANCELLED」に更新する XSL 変換を書きたいとします。

私はすべてのテレビ番組名を更新できますが、放映ステータスの値がキャンセルされた場合にのみテレビ番組名の値要素を更新する必要があることを XSL に理解させるのに苦労しています。

私が何時間もこれにこだわっていたのを助けてください!!!!

4

2 に答える 2

0

これは、プッシュ指向で、テンプレートの一致に関してもう少し簡単で、値の周りの空白の量に関係なく機能するソリューションです。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>

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

  <xsl:template
    match="content[content-detail
             [normalize-space(name) = 'Airing Status']
             [normalize-space(value) = 'Cancelled']
           ]
           /content-detail[normalize-space(name) = 'TV Show Name']/value">
    <value>
      <xsl:value-of select="concat(normalize-space(), ' -- CANCELLED')"/>
    </value>
  </xsl:template>

</xsl:stylesheet>
于 2013-07-10T17:59:30.853 に答える