XSL输出格式化

时间:2015-12-29 15:03:23

标签: xml xslt

这是XML:

<doc>
  <article>
    <texte>
      <notes>-</notes>
      <content>
        <title>T 1</title>
        <argument>Arg 1</argument>
        <dir>Foo Bar</dir>
        <act>Bar Foo</act>
        <p>Paragraph 1.1</p>
        <p>Paragraph 1.2</p>
        <p>Paragraph <i>1.3</i></p>
        <author>Fitz Beam</author>
        <short-author>FB</short-author>
      </content>
      <notes>-</notes>
      <content>
        <title>T2</title>
        <p>Paragraph 2.1</p>
        <author>John Doe</author>
        <short-author>JD</short-author>
      </content>
      <notes>-</notes>
      <content>
        <title>T3</title>
        <argument>Arg 3</argument>
        <p>Paragraph 3.1</p>
        <author>Nick Cick</author>
        <short-author>NC</short-author>
      </content>
    </texte>
  </article>
</doc>

这是xsl:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>

<xsl:template match="node()[not(self::author)]">
    <xsl:copy>
        <xsl:apply-templates select="node()[not(self::author)]"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="/doc">
    <article>
        <xsl:apply-templates select="article/texte/*"/>
    </article>
</xsl:template>

<xsl:template match="text()[not(normalize-space())]">
    <xsl:text>&#10;</xsl:text>
</xsl:template>


</xsl:stylesheet>

这就是我得到的:

<?xml version="1.0" encoding="UTF-8"?>
<article><notes>-</notes><content>
<title>T 1</title>
<argument>Arg 1</argument>
<dir>Foo Bar</dir>
<act>Bar Foo</act>
<p>Paragraph 1.1</p>
<p>Paragraph 1.2</p>
<p>Paragraph <i>1.3</i></p>

<short-author>FB</short-author>
</content><notes>-</notes><content>
<title>T2</title>
<p>Paragraph 2.1</p>

<short-author>JD</short-author>
</content><notes>-</notes><content>
<title>T3</title>
<argument>Arg 3</argument>
<p>Paragraph 3.1</p>

<short-author>NC</short-author>
</content></article>

这应该是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<article><notes>-</notes><content>
<title>T 1</title>
<argument>Arg 1</argument>
<dir>Foo Bar</dir>
<act>Bar Foo</act>
<p>Paragraph 1.1</p>
<p>Paragraph 1.2</p>
<p>Paragraph <i>1.3</i></p> <short-author>FB</short-author>
</content><notes>-</notes><content>
<title>T2</title>
<p>Paragraph 2.1</p> <short-author>JD</short-author>
</content><notes>-</notes><content>
<title>T3</title>
<argument>Arg 3</argument>
<p>Paragraph 3.1</p> <short-author>NC</short-author>
</content></article>

我需要一个空间,而不是双重换行。双重换行是省略“作者”的结果 谢谢!

0 个答案:

没有答案