0

xsltを使用してxmlをwordmlに変換しています。そのセルのコンテンツを運ぶ要素の属性が異なる場合、テーブルセルのコンテンツを別の方法でフォーマットできるようにしたいと思います。たとえば、次の xslt があります。

  <xsl:template match="/ns0:RootElement/ns0:Items/ns0:Item0">
    <w:tc>
      <w:tcPr>
        <w:tcW w:w="2268" w:type="dxa" />
        <w:noWrap />
      </w:tcPr>
      <ns0:Item0>
        <xsl:for-each select="@ns0:*|@*[namespace-uri()='']">
          <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
            <xsl:value-of select="." />
          </xsl:attribute>
        </xsl:for-each>
        <w:p wsp:rsidR="00F75372" wsp:rsidRPr="0058287E" wsp:rsidRDefault="00F75372" wsp:rsidP="0058287E">
          <w:r wsp:rsidRPr="0058287E"> <w:t><xsl:value-of select="." /></w:t></w:r>
        </w:p>
      </ns0:Item0>
    </w:tc>
  </xsl:template>

Item0 に属性が選択されているとしましょう。この属性に基づいてフォーマットを変更したいと思います。それを達成するために提示された xslt を変更する方法について何か考えはありますか? よろしく

4

2 に答える 2

1

xsl:choose が必要だと思います

http://www.w3schools.com/XSL/xsl_choose.asp

xslのif文です。

于 2009-10-16T00:55:35.530 に答える
0

これが私のために働いた解決策です:

<xsl:template match="/ns0:RootElement/ns0:Items/ns0:Item0">
    <w:tc>
      <w:tcPr>
        <w:tcW w:w="2268" w:type="dxa" />
        <w:noWrap />
          <!-- test if item0 attribute is selected and if it is, change border and background color-->
         <xsl:if test='@selected=1'>
            <w:tcBorders>
               <w:top w:val="single" w:sz="8" wx:bdrwidth="20" w:space="0" w:color="993300" />
               <w:left w:val="single" w:sz="8" wx:bdrwidth="20" w:space="0" w:color="993300" />
               <w:bottom w:val="single" w:sz="8" wx:bdrwidth="20" w:space="0" w:color="993300" />
               <w:right w:val="single" w:sz="8" wx:bdrwidth="20" w:space="0" w:color="993300" />
            </w:tcBorders>
            <w:shd w:val="clear" w:color="auto" w:fill="FF9900" wx:bgcolor="DD5800" />
         </xsl:if>
      </w:tcPr>
      <ns0:Item0>
        <xsl:for-each select="@ns0:*|@*[namespace-uri()='']">
          <xsl:attribute name="{name()}" namespace="{namespace-uri()}">
            <xsl:value-of select="." />
          </xsl:attribute>
        </xsl:for-each>
        <w:p wsp:rsidR="00F75372" wsp:rsidRPr="0058287E" wsp:rsidRDefault="00F75372" wsp:rsidP="0058287E">
            <!-- test if item0 attribute is selected and if it is, change font to bold-->
           <xsl:if test='@selected=1'>
              <w:r>
                 <w:rPr>
                    <!--<w:i w:val="on"/>-->
                    <w:b/>
                 </w:rPr>
                 <w:t>
                    <xsl:value-of select="." />
                 </w:t>
              </w:r>
           </xsl:if>
           <xsl:if test='@selected=-1'>
              <w:r wsp:rsidRPr="0058287E">
                 <w:t>
                    <xsl:value-of select="." />
                 </w:t>
              </w:r>
           </xsl:if>
        </w:p>
      </ns0:Item0>
    </w:tc>
  </xsl:template>

誰かがこれを使用するかもしれないことを願っています...

于 2009-10-19T21:47:33.307 に答える