Page 1 of 1

Exact copy of 1 line

Posted: Fri Jan 30, 2009 7:06 pm
by droomdp
I have this:

<ElA>

<SubElA><SubSubElA>someText</SubSubElA>someText<SubSubElB> some text</SubSubElB></SubElA>

</ElA>

I want to copy this in a new XML like this (on 1 line !):

<SubElA><SubSubElA>someText</SubSubElA>sometText<SubSubElB>someText</SubSubElB></SubElA>


Unfortunately I receive this (multiple lines):

<SubElA>
<SubSubElA>someText</SubSubElA>someText<SubSubElB>someText</SubSubElB>
</SubElA>

I need to have everything on 1 line.

I use this in my XSL:

<xsl:template match="ElA">
<xsl:apply-templates select="node()" mode="clone"/>

</xsl:template>


<xsl:template match="@*|node()" mode="clone">

<xsl:copy>

<xsl:apply-templates select="@*|node()" mode="clone"/>

</xsl:copy>

</xsl:template>


Is there another method to do this,
Any help is very appreciated.

Kind Regards,

Droom

Re: Exact copy of 1 line

Posted: Fri Jan 30, 2009 7:21 pm
by george
I cannot reproduce that. For me

Code: Select all


<ElA>
<SubElA><SubSubElA>someText</SubSubElA>someText<SubSubElB> some text</SubSubElB></SubElA>
</ElA>
with

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:template match="ElA">
<xsl:apply-templates select="node()" mode="clone"/>
</xsl:template>
<xsl:template match="@*|node()" mode="clone">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="clone"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
gives (with the content on a single line, this may wrap in the browser):

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<SubElA><SubSubElA>someText</SubSubElA>someText<SubSubElB> some text</SubSubElB></SubElA>
What XSLT processor are you using?

Regards,
George

Re: Exact copy of 1 line

Posted: Fri Jan 30, 2009 7:32 pm
by droomdp
george,
(already thanks for your time)

When I use this header I have everything on 1 line:
<?xml version="1.0" encoding="ISO-8859-15" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" method="xml"/>

But I only want to copy some lines, which where originaly on 1 line, to 1 line.

Right now I'm using this header:
<?xml version="1.0" encoding="ISO-8859-15" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" method="xml" indent="yes" />

I hope I'm clear anough ?

Kind Regards,

Droom

Re: Exact copy of 1 line

Posted: Fri Jan 30, 2009 9:45 pm
by george
Hi Droom,

When you specify indent="yes" you tell the XSLT processor to try to indent your file and the behaviour is very much processor dependent so you should use that only if you do not care too much about the indentation.

Best Regards,
George

Re: Exact copy of 1 line

Posted: Mon Feb 02, 2009 4:50 pm
by droomdp
George,

My problem is that I need to import this XML in another application (Adobe InDesign), which need those "line feeds" otherwise put all the text lines after each other. So I have to play with it in my XML. Or is there another method to catch this ?

Kind Regards,
Droom

Re: Exact copy of 1 line

Posted: Mon Feb 02, 2009 5:05 pm
by george
Hi Droom,

I do not understand - first you post that you get new lines as you do not want that. The cause of that is the indent set to yes that tells the XSLT processor to try to present the result in some indented form. Removing that gives exactly the output you said you want. Now you say that you need additional new lines... Maybe you can try to create a sample that shows what you have, what you need and what you got - probably it is a little more than what you shown here...

Regards,
George

Re: Exact copy of 1 line

Posted: Mon Feb 02, 2009 6:30 pm
by droomdp
George,

If I have originaly this line:
<ElA><ElB>blabla1</ElB>blabla2<ElC>blabla3</ElC><ElA>

In some cases I like to copy nested XML elements on 1 line.
f.e. <ElA><ElB>blabla1</ElB>blabla2<ElC>blabla3</ElC><ElA>

and not as:
<ElA>
<ElB>blabla1</ElB>blabla2<ElC>blabla3</ElC>
<ElA>

Because when I import this in Adobe InDesign,
In a textframe I get:
(blanc line)
blabla1blabla2blabla3
(blanc line)

And yes, as you explained earlier, I notice that te "copy" result depends also on the type of parser (saxon versus xalan for example).

I hope this Sounds more comprehensible ?

Kind Regards,
Droom

Re: Exact copy of 1 line

Posted: Mon Feb 02, 2009 11:28 pm
by george
Hi,

The solution is to not use indent="yes" on xsl:output. If you add that then you have no control on the output formatting. If you need formatting on some other part of your code you can add that in your XSLT code.

Regards,
George

Re: Exact copy of 1 line

Posted: Wed Feb 11, 2009 12:48 pm
by droomdp
George,

I'm rather new to use XSLT, so maybe a stupid question, how can I do this ?

Regards,
Droom

Re: Exact copy of 1 line

Posted: Wed Feb 11, 2009 1:35 pm
by droomdp
George,

I figured it out.
Thanks for your help, suggestion and time.

Regards,
Droom