首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >W: Open表中的标签( XML ->Open )

W: Open表中的标签( XML ->Open )
EN

Stack Overflow用户
提问于 2015-01-09 10:33:23
回答 1查看 443关注 0票数 0

我正在尝试将一个XML -文件转换为打开XML (Word)。在翻译<br/>时,在<table>中。翻译示例如下:

代码语言:javascript
运行
复制
<w:tbl>
    <w:tblPr>
        <w:tblW w:w="0" w:type="auto"/>
        <w:tblInd w:w="2160" w:type="dxa"/>
        <w:tblBorders>
            <w:top w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
            <w:left w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
            <w:bottom w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
            <w:right w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
            <w:insideH w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
            <w:insideV w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
        </w:tblBorders>
        <w:tblCellMar>
            <w:top w:w="28" w:type="dxa"/>
            <w:bottom w:w="28" w:type="dxa"/>
        </w:tblCellMar>
        <w:tblLook w:val="04A0"/>
    </w:tblPr>
    <w:tblGrid>
        <w:gridCol w:w="3629"/>
        <w:gridCol w:w="3352"/>
    </w:tblGrid>
    <w:tr wsp:rsidR="00FC1136" wsp:rsidRPr="0078376D">
        <w:trPr>
            <w:trHeight w:val="200"/>
        </w:trPr>
        <w:tc>
            <w:tcPr>
                <w:tcW w:w="4500" w:type="dxa"/>
            </w:tcPr>
            <w:p wsp:rsidR="00FC1136" wsp:rsidRPr="0078376D" wsp:rsidRDefault="00F35AB4">
                <w:pPr>
                    <w:rPr>
                        <w:rFonts w:ascii="Arial" w:h-ansi="Arial" w:cs="Arial"/>
                        <wx:font wx:val="Arial"/>
                        <w:lang w:val="EN-US"/>
                    </w:rPr>
                </w:pPr>
                <w:r wsp:rsidRPr="0078376D">
                    <w:rPr>
                        <w:lang w:val="EN-US"/>
                    </w:rPr>
                    <w:br/>
                </w:r>
                <w:r wsp:rsidRPr="0078376D">
                    <w:rPr>
                        <w:rFonts w:ascii="Arial" w:h-ansi="Arial" w:cs="Arial"/>
                        <wx:font wx:val="Arial"/>
                        <w:sz w:val="20"/>
                        <w:sz-cs w:val="20"/>
                        <w:lang w:val="EN-US"/>
                    </w:rPr>
                    <w:tab/>
                    <w:t>shift enter</w:t>
                </w:r>
            </w:p>
        </w:tc>
    </w:tr>
</w:tbl>

我在下一行得到一个额外的<w:tab/>,即使我没有将它插入到XSLT的任何位置。我怎样才能去掉这个标签?

注意:额外的w:tab-标记仅插入到表中,并在w:br-标记之后插入。

XSLT的一部分(完整的代码是几百行,我希望这足够了):

代码语言:javascript
运行
复制
<xsl:template match="br"><w:br/></xsl:template>
<xsl:template match="table">
    <xsl:variable name="totCol">
        <xsl:value-of select="count(tbody/tr[1]/td)"/>
    </xsl:variable>
    <xsl:variable name="totRow">
        <xsl:value-of select="count(tbody/tr)"/>
    </xsl:variable>
    <xsl:variable name="height">
        <xsl:if test="not(contains(@style, 'height'))">
            <xsl:value-of select="600 div $totRow"/>
        </xsl:if>
        <xsl:if test="contains(@style, 'height')">
            <xsl:value-of select="(substring-before(substring-after(@style,'height:'),'px')) * 12 div $totRow"/>
        </xsl:if>
    </xsl:variable>
    <xsl:variable name="width">
        <xsl:if test="not(contains(@style, 'width'))">
            <xsl:value-of select="9250 div $totCol"/>
        </xsl:if>
        <xsl:if test="contains(@style, 'width')">
            <xsl:value-of select="(substring-before(substring-after(@style,'width:'),'px')) * 18 div $totCol"/>
        </xsl:if>
    </xsl:variable>
    <xsl:variable name="indent">
        <xsl:value-of select="(count(ancestor::ul)+count(ancestor::ol)) * 720"/>
    </xsl:variable>
    <w:tbl>
        <w:tblPr>
            <w:tblW w:w="0" w:type="auto"/>
            <w:tblInd w:w="{$indent}" w:type="dxa"/>
            <w:tblBorders>
                <w:top w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
                <w:left w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
                <w:bottom w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
                <w:right w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
                <w:insideH w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
                <w:insideV w:val="double" w:sz="4" wx:bdrwidth="30" w:space="0" w:color="auto"/>
            </w:tblBorders>
            <w:tblCellMar>
                <w:top w:w="28" w:type="dxa"/>
                <w:bottom w:w="28" w:type="dxa"/>
            </w:tblCellMar>
            <w:tblLook w:val="04A0"/>
        </w:tblPr>
        <w:tblGrid>
            <xsl:for-each select="(tbody/tr)">
                <w:gridCol w:w="{$width}"/>
            </xsl:for-each>
        </w:tblGrid>
        <xsl:for-each select="(tbody/tr)">
            <w:tr>
                <w:trPr>
                    <w:trHeight w:val="{$height}"/>
                </w:trPr>
                <xsl:for-each select="(td)">
                    <w:tc>
                        <w:tcPr>
                            <w:tcW w:w="{$width}" w:type="dxa"/>
                        </w:tcPr>
                        <xsl:if test="count(text())>0"><w:p><xsl:apply-templates select="text()" /></w:p></xsl:if>
                        <xsl:apply-templates select="table" />
                    </w:tc>
                </xsl:for-each>
            </w:tr>
        </xsl:for-each>
    </w:tbl>
    <xsl:if test="count(following-sibling::p|ol|ul)=0"><w:p/></xsl:if>
</xsl:template>
<xsl:template match="text()[normalize-space()]">
<!-- When text() does not has any HTML-Tags -->
<xsl:if test="name(..) = 'field'">
    <w:p>
        <w:pPr>
            <w:rFonts w:ascii="Arial" w:h-ansi="Arial" w:cs="Arial" />
            <wx:font wx:val="Arial" />
            <w:sz w:val="20" />
            <w:sz-cs w:val="20" />
        </w:pPr>
        <w:r>
            <w:rPr>
                <!--w:spacing w:before="300" w:after="60" /-->
                <w:rFonts w:ascii="Arial" w:h-ansi="Arial" w:cs="Arial" />
                <wx:font wx:val="Arial" />
                <w:sz w:val="20" />
                <w:sz-cs w:val="20" />
            </w:rPr>
            <w:t>
                <xsl:copy-of select="."/>
            </w:t>
        </w:r>
    </w:p>
  </xsl:if>
  <xsl:if test="name(..) != 'field'">
    <w:pPr>
        <xsl:for-each select="ancestor-or-self::*">
            <xsl:call-template name="ancestorStyle">
                <xsl:with-param name="ancestorName">
                    <xsl:value-of select="name()"/>
                </xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>

        <xsl:call-template name="hdl-styles">
            <xsl:with-param name="sstyles">
                <xsl:for-each select="ancestor-or-self::*/@style">
                    <xsl:value-of select="concat(.,';')"/>
                </xsl:for-each>
            </xsl:with-param>
        </xsl:call-template>
    </w:pPr>
    <w:r>
        <w:rPr>
            <xsl:for-each select="ancestor-or-self::*">
                <xsl:call-template name="ancestorStyle">
                    <xsl:with-param name="ancestorName">
                        <xsl:value-of select="name()"/>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:for-each>
            <xsl:call-template name="hdl-styles">
                <xsl:with-param name="sstyles">
                    <xsl:for-each select="ancestor-or-self::*/@style">
                        <xsl:value-of select="concat(.,';')"/>
                    </xsl:for-each>
                </xsl:with-param>
            </xsl:call-template>
        </w:rPr>
        <w:t>
            <xsl:copy-of select="."/>
        </w:t>
    </w:r>
  </xsl:if>
</xsl:template>

资料来源:

代码语言:javascript
运行
复制
<table border="1" cellpadding="1" cellspacing="1" style="width: 500px">
    <tbody>
        <tr>
            <td>
            <p>first line</p>
            <p>line break</p>
            <p>line break<br />
            shift enter<br />
            lvl3 table</p>
            </td>
            <td> </td>
        </tr>
        <tr>
            <td> </td>
            <td> </td>
        </tr>
        <tr>
            <td> </td>
            <td> </td>
        </tr>
    </tbody>
</table>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-12 14:42:17

代码语言:javascript
运行
复制
<p>line break<br />
shift enter<br />
lvl3 table</p>

<p>中的标记<p>之后,有一个选项卡在Open中自动转换为<w:tab/>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27858631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档