2

アイテムのプロパティは、@properties 属性にスペースで区切られた用語としてリストされます。プロパティのマスター リストもあります。

<t>

   <items>
     <item id='a' properties='red little' />
     <item id='b' properties='big strong heavy' />
     <item id='c' properties='blue heavy' >
   </items>

   <properties>
     <property id='red' />
     <property id='little' />
     <property id='blue' />
   </properties>

</t>

私の問題: XLST 1.0 を使用して、プロパティのマスター リストに少なくとも 1 つのプロパティを持つすべてのアイテムに一致するテンプレートの一致属性を記述します。

項目 a と c は一致します。アイテムbはそうではありません。

XSLT 1.0なので、str:splitが使えません。多分キーとcontains()を使った何か?

4

3 に答える 3

1

あなたも使えます<xsl:if>か?

<xsl:template match="item">
    <xsl:if test="/t/properties/property[contains(concat(' ', current()/@properties, ' '), concat(' ', @id, ' '))]">
        ...
    </xsl:if>
</xsl:template>

残念ながら、属性current()内では使用できません。match

于 2012-12-25T21:15:35.683 に答える
1

current()I.キーと:)を使用したもう1つのソリューション

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

 <xsl:key name="kItemByProp" match="item"
  use="boolean(/*/properties/property/@id
                 [contains(concat(' ', current()/@properties, ' '),
                           .)]
              )"/>

 <xsl:template match=
  "item[count(.| key('kItemByProp', 'true'))
       =
        count(key('kItemByProp', 'true'))
        ]
  ">
  <xsl:copy-of select="."/>
 </xsl:template>
</xsl:stylesheet>

この変換が提供された XML ドキュメントに適用されると、次のようになります。

<t>
    <items>
        <item id='a' properties='red little' />
        <item id='b' properties='big strong heavy' />
        <item id='c' properties='blue heavy' />
    </items>
    <properties>
        <property id='red' />
        <property id='little' />
        <property id='blue' />
    </properties>
</t>

必要な正しい結果が生成されます。

<item id="a" properties="red little"/>
<item id="c" properties="blue heavy"/>

Ⅱ.キーはありませんが、テンプレート本体の最も外側に条件付き命令があります。

 <xsl:template match="item">
  <xsl:if test=
  "/*/properties/*/@id
        [contains(concat(' ', current()/@properties, ' '), .)]">
    <!-- Your processing here -->
  </xsl:if>
 </xsl:template>

完全な変換は次のとおりです。

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

 <xsl:template match="item">
  <xsl:if test=
  "/*/properties/*/@id
        [contains(concat(' ', current()/@properties, ' '), .)]">
    <xsl:copy-of select="."/>
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>

この変換を同じ XML ドキュメント (上記) に適用すると、同じ正しい結果が生成されます。

<item id="a" properties="red little"/>
<item id="c" properties="blue heavy"/>
于 2012-12-25T22:58:45.020 に答える