Format and indent problem

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Zingo
Posts: 2
Joined: Sun Sep 07, 2008 1:42 pm

Format and indent problem

Post by Zingo »

Hi!

I have a little problem when using Format and Indent on a huge xml math book I'm working on. We use two span class attributes aka
<span class="exercisenumber">
and
<span class="exercisepart">

Can I somehow configure the format and indent to leave them as they are and not
put everything in one big chunk like:

<span class="exercisepart">a</span> Bestäm funktionen A(x). <span class="exercisepart">b</span> Bestäm funktionens definitionsmängd. <span class="exercisepart">c</span> Bestäm funktionens värdemängd.

I want it like this:
<span class="exercisepart">a</span>
Bestäm funktionen A(x).
<span class="exercisepart">b</span>
Bestäm funktionens definitionsmängd.
<span class="exercisepart">c</span>
Bestäm funktionens värdemängd.

Is that possible?

Would also be great to format
<p>
<span class="exercisenumber">1</span> Gör en värdetabell.</p>

to
<p>
<span class="exercisenumber">1</span>
Gör en värdetabell.
</p>


Everything else seems to work ok, it's just that these little issues makes it kind of hard to read. If anyone got ay hint I would really appreciate it. So is it possible to add class attributes and tell the indenter how to handle them? I have tried everything except adding something in "Preserve space elements (XPath)" as I'm not sure how that works.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Format and indent problem

Post by sorin_ristache »

Hello,

You should add an XPath expression corresponding to the elements that you want to preserve to the list Preserve space elements (XPath) available from Preferences / Editor / Format / XML. If you know the paths for the parent of the span elements and for the p element, for example /root/a/b and /root/c/p as in the following document:

Code: Select all

<root>
<a>
<b>
<span class="exercisepart">a</span>
Bestäm funktionen A(x).
<span class="exercisepart">b</span>
Bestäm funktionens definitionsmängd.
<span class="exercisepart">c</span>
Bestäm funktionens värdemängd.
</b>
</a>
<c>
<p>
<span class="exercisenumber">1</span>
Gör en värdetabell.
</p>
</c>
</root>
then you must add the paths /root/a/b and /root/c/p to the list Preserve space elements (XPath). If the span and p elements can have different paths in the document you can add the expressions //b and //p to the list Preserve space elements (XPath).

Other option is to add the attribute xml:space="preserve" in the XML document to the elements which you want to preserve when you apply the Format and Indent action, in your case the b and c elements that contain span and p elements, like this:

Code: Select all

<root>
<a>
<b xml:space="preserve">
<span class="exercisepart">a</span>
Bestäm funktionen A(x).
<span class="exercisepart">b</span>
Bestäm funktionens definitionsmängd.
<span class="exercisepart">c</span>
Bestäm funktionens värdemängd.
</b>
</a>
<c>
<p xml:space="preserve">
<span class="exercisenumber">1</span>
Gör en värdetabell.
</p>
</c>
</root>
Regards,
Sorin
Zingo
Posts: 2
Joined: Sun Sep 07, 2008 1:42 pm

Re: Format and indent problem

Post by Zingo »

Thx for the insight Sorin but I'm not sure this is working. The
<span class="exercisenumber"> and <span class="exercisepart"> can be anywhere in the document and have all kinds of ancestors so there is not one particular path.

I tried adding these xpath expressions but they have no effect:

Code: Select all

//span[@class='exercisenumber']
and

Code: Select all

//span[@class='exercisepart']
As documented here http://www.w3schools.com/XPath/xpath_syntax.asp in the example

Code: Select all

//title[@lang='eng']
Selects all the title elements that have an attribute named lang with a value of 'eng'
Are these kinds of xpath expressions possible or am I doing something wrong?
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Format and indent problem

Post by sorin_ristache »

Hello,

As you can read in the dialog for adding an XPath expression to the list Preserve space elements (XPath) available from Preferences / Editor / Format / XML in the current version only the displayed types of simple XPath expressions are allowed, for example //span or /root/parent/span. The expression that you used includes an attribute and it will be ignored.

Also you have the option of adding the attribute xml:space="preserve" to an element that you want to preserve as it is. You can add this attribute to the parent elements of <span class="exercisenumber"> and <span class="exercisepart"> where you want to preserve the formatting.


Regards,
Sorin
Post Reply