I use an xslt to get some ID attribute..when new xml file is built..
Here is a input xml file..


<page num="App. A-1"/>
<title>Appendix A</title>
<subtitle>The Thompson Memorandum</subtitle>
<para align="left"><content-style font-style="bold">U.S. Department of Justice</content-style></para>
<para>Office of the Deputy Attorney General</para>
<para>The Deputy Attorney General</para>
<para>January 20, 2003</para>
<table frame="none" width="100%">
<tgroup cols="2">
<colspec align="left" colname="col1" colnum="1" colwidth="25"/>
<colspec align="left" colname="col2" colnum="2" colwidth="75"/>
<tbody>
<row>
<entry namest="col1" nameend="col2"><para><content-style format="underline">MEMORANDUM</content-style></para></entry>
</row>
<row>
<entry><para>TO:</para></entry>
<entry><para>Heads of Department Components United States Attorneys</para></entry>
</row>
<row>
<entry><para>FROM:</para></entry>
<entry><para>Larry D. Thompson Deputy Attorney General</para></entry>
</row>
<row>
<entry><para>SUBJECT:</para></entry>
<entry><para><content-style format="underline">Principles of Federal Prosecution of Business Organizations</content-style></para></entry>
</row>
</tbody>
</tgroup>

New XML file is like this..

<page num="App. A-1"/><title>Appendix A</title><subtitle>The Thompson Memorandum</subtitle><para align="left"><content-style font-style="bold">U.S. Department of Justice</content-style></para><para>Office of the Deputy Attorney General</para><para>The Deputy Attorney General</para><para>January 20, 2003</para><table frame="none" width="100%" id="tab_chap_001"><tgroup cols="2"><colspec align="left" colname="col1" colnum="1" colwidth="25"/><colspec align="left" colname="col2" colnum="2" colwidth="75"/><tbody><row><entry namest="col1" nameend="col2"><para><content-style format="underline">MEMORANDUM</content-style></para></entry></row><row><entry><para>TO:</para></entry><entry><para>Heads of Department Components United States Attorneys</para></entry></row><row><entry><para>FROM:</para></entry><entry><para>Larry D. Thompson Deputy Attorney General</para></entry></row><row><entry><para>SUBJECT:</para></entry><entry><para><content-style format="underline">Principles of Federal Prosecution of Business Organizations</content-style></para></entry></row></tbody></tgroup>

I need to get xml file in same format...
It need hard returns..
<xsl:output indent="yes"> give indent file but not the same as input..


Can any one help me???


thanks,
Parth Mishra

Dani AI

Generated

Brief summary and cause: the XSLT processor builds an output tree, and the serializer decides whether to "pretty print" that tree. As noted, xsl:output indent="yes" asks the serializer to add indentation but does not reproduce the exact line breaks from the input. To guarantee a hard return in the serialized output you must produce an explicit text node containing a newline during the transformation.

Practical recipe: emit a newline with xsl:text where you need it. The common pattern is to add &#10; (LF) after elements you want on their own line, or emit &#13;&#10; for CR+LF if the consumer needs Windows style. Example that adds a newline after each copied child element:

<xsl:output method="xml" indent="no"/>

<xsl:template match="root/*">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
  <xsl:text>&#10;</xsl:text>
</xsl:template>

Notes and alternatives: use xsl:preserve-space / xsl:strip-space to control whether whitespace-only text nodes from the source are available to copy (see the spec). If the goal is to preserve the source byte-for-byte formatting, XSLT is not the right tool — it works with the logical XML tree, not the original file layout. Avoid disable-output-escaping for line breaks; it is unreliable across processors and serializers.

References: see the W3C XSLT spec on xsl:text and xsl:output for exact behavior and serializer notes: xsl:text and xsl:output.

Is whitespace in your output document really critical? The output indenting just makes the output tree look pretty by inserting returns and tabs as needed for a tree.

If you really need to insert line break and whitespace in the output tree, you'll need to add them in as part of your transformation.

Check out this link above. It offers a lot of suggestions about escaped characters and whitespace in XSLT. You should find what you're looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.