Re: [xsl] Node's content modification

Subject: Re: [xsl] Node's content modification
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sat, 8 Sep 2001 16:16:34 +0100
Hi Auguste,

> In the xml-schema file for this instance document i fixed the
> maximum length of the elements "string" and "integer" to say: 5

Your first problem is that XSLT/XPath doesn't have access to the
post-schema-validation infoset (PSVI), so the stylesheet doesn't know
that the maximum length of the two elements needs to be 5. Getting
hold of that information is not particularly straight-forward, and a
different question.

> I wrote a xslt-file to transform the xml- to an ascii-file.The
> problem ist that: i want in the ascii-file the maximum length of
> each element to be reach in this way:
> - if the element is a string or derived from it i fill it with space
> to reach the maximum length(after it)
>  - if it is an integer i write "0" prior to it.
> For the example document beyond the result should be like:
>  "xml  00123" but i always became it this way:"xml123"

You can pad a string within 5 spaces with:

  substring(concat($string, '     '), 1, 5)

You can pad an integer within 5 0s with:

  format-number($integer, '00000')

If the length can vary (which would be the case if you were retrieving
it from the schema document) then you need a template for constructing
the string. If you have a good idea of the maximum length it could
possibly be, you can create a string of that length and substring it
as desired to get the length you need. Otherwise, you might have a
look at the str:padding template from for ideas about how to
build it.

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread