OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

XSL Line Breaks/Indentation - Please !!!



Hi
 
Does anyone know how to put a line break in XSL ?  I am trying to transform one XML file to another XML file using XSL. However, resulting XML doesn't have the formatting (line breaks, indentation etc) which is in the Source XML.
 
My Source XML is as follows:
 
<PRODUCT xml:lang="en">
 <PRODUCTID>1234</PRODUCTID>
 <PRODUCTNAME>Producers product name</PRODUCTNAME>
 <MANUFACTURERNAME>Manufactorer name</MANUFACTURERNAME>
 <MANUFACTURERPRODUCTNAME>Manufacturers product name</MANUFACTURERPRODUCTNAME>
 <BRANDNAME>Brandname</BRANDNAME>
 <EXTRAID>2345</EXTRAID>
 <EXTRAIDQ>MK</EXTRAIDQ>
 <EXTRAID>4567</EXTRAID>
 <EXTRAIDQ>MF</EXTRAIDQ>
 <KEYWORD>Keyword1</KEYWORD>
 <KEYWORD>Keyword2</KEYWORD>
</PRODUCT>
<PRODUCT xml:lang="en">
 <PRODUCTID>4321</PRODUCTID>
 <PRODUCTNAME>Producers product name</PRODUCTNAME>
 <MANUFACTURERNAME>Manufactorer name</MANUFACTURERNAME>
 <MANUFACTURERPRODUCTNAME>Manufacturers product name</MANUFACTURERPRODUCTNAME>
 <BRANDNAME>Brandname</BRANDNAME>
 <EXTRAID>2345</EXTRAID>
 <EXTRAIDQ>MK</EXTRAIDQ>
 <EXTRAID>4567</EXTRAID>
 <EXTRAIDQ>MF</EXTRAIDQ>
 <KEYWORD>Keyword1</KEYWORD>
 <KEYWORD>Keyword2</KEYWORD>

</PRODUCT>
 
 
And I use the following XSL to convert this to another XML:
 
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 
 <xsl:output indent="yes"/>
 <xsl:template match="PRODUCTS">
  <xsl:copy>
   <xsl:apply-templates select="PRODUCT"/>
  </xsl:copy>
 </xsl:template>
 <xsl:template match="PRODUCT">
  <xsl:variable name="attribValue">
   <xsl:value-of select="@xml:lang"/> <!-- get the xml:lang into a variable-->
  </xsl:variable>
  <!-- set <PRODUCT xml:lang="xx">  -->
  <xsl:text disable-output-escaping="yes">&lt;PRODUCT xml:lang="</xsl:text>
  <xsl:value-of select="$attribValue"/> 
  <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
  <xsl:copy-of select="PRODUCTID"/>
  <xsl:copy-of select="PRODUCTNAME"/>
  <xsl:copy-of select="MANUFACTURERPRODUCTNAME"/>
  <xsl:copy-of select="BRANDNAME"/>      
 
  <xsl:for-each select="EXTRAID">
   <xsl:element name="PRODUCTID">
    <xsl:attribute name="QUALIFIER">
     <xsl:value-of select="following-sibling::*"/>
    </xsl:attribute>
    <xsl:value-of select="."/>
   </xsl:element>
  </xsl:for-each>
 
  <xsl:for-each select="KEYWORD">
   <xsl:text disable-output-escaping="yes">&lt;KEYWORD xml:lang="</xsl:text>
   <xsl:value-of select="$attribValue"/> 
   <xsl:text disable-output-escaping="yes">"&gt;</xsl:text>
   <xsl:value-of select="."/>
   <xsl:text disable-output-escaping="yes">&lt;/KEYWORD&gt;</xsl:text>
  </xsl:for-each>
 
  <xsl:text disable-output-escaping="yes">&lt;/PRODUCT&gt;</xsl:text>
 
 </xsl:template>
</xsl:stylesheet>
 
And the output XML I get is as follows:
 
<?xml version="1.0" encoding="UTF-8"?>
<PRODUCTS><PRODUCT xml:lang="en"><PRODUCTID>1234</PRODUCTID>
<PRODUCTNAME>Producers product name</PRODUCTNAME>
<MANUFACTURERPRODUCTNAME>Manufacturers product name</MANUFACTURERPRODUCTNAME>
<BRANDNAME>Brandname</BRANDNAME>
<PRODUCTID QUALIFIER="MK">2345</PRODUCTID>
<PRODUCTID QUALIFIER="MF">4567</PRODUCTID><KEYWORD xml:lang="en">Keyword1</KEYWORD><KEYWORD xml:lang="en">Keyword2</KEYWORD></PRODUCT><PRODUCT xml:lang="en"><PRODUCTID>4321</PRODUCTID>
<PRODUCTNAME>Producers product name</PRODUCTNAME>
<MANUFACTURERPRODUCTNAME>Manufacturers product name</MANUFACTURERPRODUCTNAME>
<BRANDNAME>Brandname</BRANDNAME>
<PRODUCTID QUALIFIER="MK">2345</PRODUCTID>
<PRODUCTID QUALIFIER="MF">4567</PRODUCTID><KEYWORD xml:lang="en">Keyword1</KEYWORD><KEYWORD xml:lang="en">Keyword2</KEYWORD></PRODUCT><PRODUCT xml:lang="en"><PRODUCTID>5678</PRODUCTID>
<PRODUCTNAME>Producers product name</PRODUCTNAME>
<MANUFACTURERPRODUCTNAME>Manufacturers product name</MANUFACTURERPRODUCTNAME>
<BRANDNAME>Brandname</BRANDNAME>
<PRODUCTID QUALIFIER="MK">2345</PRODUCTID>
<PRODUCTID QUALIFIER="MF">4567</PRODUCTID><KEYWORD xml:lang="en">Keyword1</KEYWORD><KEYWORD xml:lang="en">Keyword2</KEYWORD></PRODUCT><PRODUCT xml:lang="en"><PRODUCTID>8765</PRODUCTID>
<PRODUCTNAME>Producers product name</PRODUCTNAME>
<MANUFACTURERPRODUCTNAME>Manufacturers product name</MANUFACTURERPRODUCTNAME>
<BRANDNAME>Brandname</BRANDNAME>
<PRODUCTID QUALIFIER="MK">2345</PRODUCTID>
<PRODUCTID QUALIFIER="MF">4567</PRODUCTID><KEYWORD xml:lang="en">Keyword1</KEYWORD><KEYWORD xml:lang="en">Keyword2</KEYWORD></PRODUCT><PRODUCT xml:lang="en"><PRODUCTID>9012</PRODUCTID>
<PRODUCTNAME>Producers product name</PRODUCTNAME>
<MANUFACTURERPRODUCTNAME>Manufacturers product name</MANUFACTURERPRODUCTNAME>
<BRANDNAME>Brandname</BRANDNAME>
<PRODUCTID QUALIFIER="MK">2345</PRODUCTID>
<PRODUCTID QUALIFIER="MF">4567</PRODUCTID><KEYWORD xml:lang="en">Keyword1</KEYWORD><KEYWORD xml:lang="en">Keyword2</KEYWORD></PRODUCT></PRODUCTS>
 
However, I need to have this Output XML to be look like the format of the source XML (with indentation, line breaks etc.). Could someone please tell me how to do this ?
 
Thanks a lot
 
Thushara