-2

以下は良い例ですが、値を動的に保存するにはどうすればよいですか....説明していただけますか?

 <xsl:variable name="countries" select="'EG, KSA, UAE, AG'" />
   <xsl:variable name="country"   select="'KSA'" />
     <xsl:choose>
      <xsl:when test="
      contains(
       concat(', ', normalize-space($countries), ', ')
        concat(', ', $country, ', ')
       )
     ">
 <xsl:text>IN</xsl:text>
 </xsl:when>
 <xsl:otherwise>
 <xsl:text>OUT</xsl:text>
</xsl:otherwise>

よく見てください....私には別の要件があります。これを調べていただけますか?

 <xml>
   <test>
    <BookID>
      0061AB
    </BookID>
    <amount>
      16
    </amount>
   </test>
   <test>
    <BookID>
      0062CD
    </BookID>
    <amount>
      2
    </amount>
   </test>
   <test>
    <BookID>
      0061AB
    </BookID>
    <amount>
      2
    </amount>
   </test>
 </xml>

ここで BookID の等しい値に従って、amount の値を追加したい...上記の例のように、BookID の値が 0061AB の場合、amount の値は 18 になるはずです。

4

1 に答える 1

0

他の人が述べているように、あなたの質問はあまり明確ではありませんが、呼び出しテンプレートを使用して、候補国と検索リストの両方を含むxmlドキュメント全体で「国の検索」アルゴリズムを再利用できます(documentロードスプリットに使用することもできます候補と検索ターゲットを別々のxmlドキュメントに)

たとえば、XSLTを適用する場合:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="/xml">
    <xsl:apply-templates select="test"/>
  </xsl:template>

  <xsl:template match="test">
    <xsl:call-template name="FindCountry">
      <xsl:with-param name="countries" select="normalize-space(countries/text())"/>
      <xsl:with-param name="country" select="normalize-space(country/text())"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="FindCountry" xml:space="default">
    <xsl:param name="countries" />
    <xsl:param name="country" />
    Is <xsl:value-of select="$country" /> in <xsl:value-of select="$countries" /> ?
    <xsl:choose>
      <xsl:when test="contains(concat(', ', $countries, ', '),
                               concat(', ', $country, ', '))">
        <xsl:text>IN</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>OUT</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

XMLへ

<xml>
  <test>
    <countries>
      EG, KSA, UAE, AG
    </countries>
    <country>
      UAE
    </country>
  </test>
  <test>
    <countries>
      GBR, USA, DE, JP
    </countries>
    <country>
      AUS
    </country>
  </test>
</xml>

結果

Is UAE in EG, KSA, UAE, AG ? IN 
Is AUS in GBR, USA, DE, JP ? OUT
于 2012-10-05T05:07:30.093 に答える