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 回答