Tuesday, 29 December 2015

XML : XSL output formating

This is the 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>    

and this is the 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>    

This is what i get:

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

and this is what it should look like:

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

Instead of the double line-break I need a space. The double line-breaks are the result of omitting the «author».
Thanks!

No comments:

Post a Comment