Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 基于元素属性的样式?_Xml_Xslt_Wordml - Fatal编程技术网

Xml 基于元素属性的样式?

Xml 基于元素属性的样式?,xml,xslt,wordml,Xml,Xslt,Wordml,我正在使用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:no

我正在使用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来实现这一点吗?
关于

我想您需要xsl:choose


这是xsl的if语句。

这里有一个对我有用的解决方案:

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


希望有人能使用这个…

我想我也可以使用xsl:if,因为我只使用了两个值,但问题是如何修改xslt以包含这个if/choose语句