我有一个xslt模板和一个xml文档,如下所示:
通常,xml中的任何数据都会像这样导出:
<Cell><Data ss:Type="String">sss</Data></Cell>
我想在xslt中进行一些更改:如果记录对象中的任何值包含<br/>
,它应该导出如下数据:
<Cell ss:StyleID="s62"><Data ss:Type="String">sss</Data></Cell>
任何人都可以帮助我吗?
Xslt模板:
<xsl:stylesheet version="1.0"
xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<xsl:template match="/">
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<Styles>
<Style ss:ID="s62">
<Alignment ss:Vertical="Bottom" ss:WrapText="1"/>
</Style>
</Styles>
<xsl:apply-templates/>
</Workbook>
</xsl:template>
<xsl:template match="/*">
<Worksheet>
<xsl:attribute name="ss:Name">
<xsl:value-of select="local-name(/*/*)" />
</xsl:attribute>
<Table x:FullColumns="1" x:FullRows="1">
<Row>
<xsl:for-each select="*[position() = 1]/*">
<Cell><Data ss:Type="String">
<xsl:value-of select="local-name()" />
</Data></Cell>
</xsl:for-each>
</Row>
<xsl:apply-templates/>
</Table>
</Worksheet>
</xsl:template>
<xsl:template match="/*/*">
<Row>
<xsl:apply-templates/>
</Row>
</xsl:template>
<xsl:template match="/*/*/*">
<Cell ss:StyleID="s62"><Data ss:Type="String">
<xsl:value-of select="." />
</Data></Cell>
</xsl:template>
</xsl:stylesheet>
Xml文档:
<records>
<record>
<BASLAMA_TARIH>2012-11-02T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-02T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>1620.88</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>1535.56</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-25T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-25T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>641.46</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>615.79</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-19T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-19T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>sss</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>829.58</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-10-26T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-10-26T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>26.25</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>25</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-29T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-29T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058934</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>284.68</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>254.62</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-02T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-02T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058937</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>464.67</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>415.31</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-21T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-21T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2468.4</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>2355.32</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-05T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-05T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058931</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>281.53</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>251.8</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-11T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-11T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058940</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>284.68</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>254.62</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-24T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-24T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058944</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>281.53</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>251.8</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-09T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-09T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>1129.6</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>1072.17</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-28T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-28T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>0</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>0</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-10T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-10T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>354.76</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>354.76</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-22T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-22T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2926.57</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>2789.97</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-29T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-29T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2531.84</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>2414.73</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-30T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-30T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058932</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>281.53</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>251.8</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-30T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-30T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018106146</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>453.55</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>405.39</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-10T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-10T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058938</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>0</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>0</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-16T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-16T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>4912.66</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>4655.07</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-13T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-13T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2313.17</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>2211.51</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-14T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-14T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>4061.73</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>3867.42</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-23T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-23T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018166873</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>257.79</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>230.61</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-25T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-25T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018097884</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>547.61</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>489.37</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-07T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-07T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058926</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>346.04</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>309.4</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-10-30T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-02-07T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>-146.38</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>-139.41</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-03T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-03T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>1143.59</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>1089.13</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-05T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-05T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2658.48</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>2531.88</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-24T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-24T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2331.96</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>2231.19</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-17T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-17T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>161.43</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>161.43</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-27T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-27T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>759.56</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>759.56</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-08T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-08T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>172.23</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>161.64</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-12T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-12T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>1073.5</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>1019.13</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-06T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-06T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2846.11</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>2712.64</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-23T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-23T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>8747.19</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>8335.29</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-04T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-04T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>826.45</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>798.53</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-01T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-01T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2061.93</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>1967.81</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-18T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-18T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2580.77</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>2453.35</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-30T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-30T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>729.09</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>705.05</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-15T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-15T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>1862.96</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>1772.08</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-14T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-14T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058939</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>281.53</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>251.8</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-03T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-03T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058942</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>431.24</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>385.48</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-26T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-26T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>585.76</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>558.39</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-07T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-07T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>1162.81</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>1105.44</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-24T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-24T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO>101000018058929</CF_ONCEKI_POLICE_NO>
<CF_SUM_BRUT_PRIM>281.53</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>251.8</CF_SUM_NET_PRIM>
</record>
<record>
<BASLAMA_TARIH>2012-11-11T00:00:00</BASLAMA_TARIH>
<BITIS_TARIH>2013-11-11T00:00:00</BITIS_TARIH>
<CF_ONCEKI_POLICE_NO />
<CF_SUM_BRUT_PRIM>2004.01</CF_SUM_BRUT_PRIM>
<CF_SUM_NET_PRIM>1908.58</CF_SUM_NET_PRIM>
</record>
答案 0 :(得分:2)
一种方法是
<xsl:template match="/*/*/*">
<Cell>
<xsl:if test=".//br">
<xsl:attribute name="ss:StyleID">s62</xsl:attribute>
</xsl:if>
<Data ss:Type="String"><xsl:value-of select="." /></Data>
</Cell>
</xsl:template>
根据后代ss:StyleID
元素的存在/不存在有条件地添加<br>
属性。但是,<br>
不会出现在生成的<Data>
元素中,因为您使用的是<xsl:value-of>
(它只是为您提供了纯文本字符串值)。您可能希望使用<xsl:copy-of select="node()"/>
,这将保留子元素的元素结构。