Page 1 of 1

Suppress default attributes in XML result of an XSLT

Posted: Sun Dec 28, 2008 3:56 pm
by dvidab
My (seemingly?) simple problem is this:
I use an XSL Transformation to convert some custom-TEI-XML into proper TEI-conforming XML. The result contains a lot of default attributes which I do not add myself but which are somehow added along the way.

E.g., the instruction:

Code: Select all

    <xsl:template match="div">
<xsl:element name="div">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
transforms an original

Code: Select all

<div n="1">
into

Code: Select all

<div type="chapter" n="1" org="uniform" sample="complete" part="N">
How can I suppress generation of all these default but optional (and thus not really necessary) attributes?

I have spent some time googling this, but haven't been lucky yet. I'm being told that the problem isn't with XSLT, but rather with the XML Parser, who's adding the stuff in the source tree already?

about the XML source ...

Posted: Sun Dec 28, 2008 7:12 pm
by dvidab
I should add that my source XML document is associated with a DTD via the <!DOCTYPE ...> declaration; this DTD is a (local) custom TEI DTD generated with the Roma tool. It's from this DTD that the parser knows about the default attributes, I guess.

Any ideas on how to get rid of the default attrs in a sensible way? Thanks!

Re: Suppress default attributes in XML result of an XSLT

Posted: Sun Dec 28, 2008 11:02 pm
by george
Yes, the parser reads the default values from the DTD.
The XSLT processor does not know which are from the XML file and which were added as defaults. The solution is to remove the DTD declaration from the file before processing it. You may also consider using a Relax NG schema instead of a DTD?

Best Regards,
George

Re: Suppress default attributes in XML result of an XSLT

Posted: Mon Dec 29, 2008 1:52 am
by dvidab
Oh right, thanks. I'm new to the XSL world and haven't yet grasped everything fully.

So, what's with the Relax NG, does the problem not exist there? I'm not particularly bound to a DTD, so if it's easier to use RNG I could switch in a minute ...

Re: Suppress default attributes in XML result of an XSLT

Posted: Mon Dec 29, 2008 11:25 am
by george
Relax NG does not add default values to the document, it just validates it. The latest version of TEI, P5 uses Relax NG as default schemas.

Regards,
George

Re: Suppress default attributes in XML result of an XSLT

Posted: Mon Dec 29, 2008 12:02 pm
by dvidab
OK, that helps, thanks a lot!

leave namespace unspecified if unambiguous?

Posted: Mon Jan 05, 2009 12:22 pm
by dvidab
Uhm ... I have a follow-up question to this.

Now that I'm using Relax NG for my document, I can no longer make use of a useful feature of DTD, namely: not needing to specify namespace prefixes if the element name is unambiguous. As far as I can tell from the Relax NG spec I must always use a namespace prefix (or the "xmlns" attribute) in the elements which are not in the declared default namespace.

For example, in my custom TEI schema I have added an element

Code: Select all

<ved>
which I'm using extremely frequently (it doesn't collide with anything in the TEI). Since it isn't in the TEI namespace I would now always have to write

Code: Select all

<myns:ved>
Is it possible somehow to leave the namespace unspecified if it is unambiguous anyway (Note that it works like that with DTD!)?

Re: Suppress default attributes in XML result of an XSLT

Posted: Tue Jan 06, 2009 2:20 pm
by george
DTDs are not namespace aware. Probably when you used a DTD you had both TEI defined elements and your element in no namespace.

TEI P5 defines all the elements in the http://www.tei-c.org/ns/1.0 namespace. Now, if you also define an element in another namespace then you need to enter that correctly in XML, that means declaring its namespace and using that when you enter the element.

Best Regards,
George

Re: Suppress default attributes in XML result of an XSLT

Posted: Tue Jan 06, 2009 3:04 pm
by george
As a followup: if you define your element in the same namespace as TEI then you will be able to enter that as you enter any TEI element, without the need to declare another namespace.

Regards,
George

Re: Suppress default attributes in XML result of an XSLT

Posted: Tue Jan 06, 2009 7:14 pm
by dvidab
Thank you for this clarification.

Declaring my elements to be in the TEI namespace sounds like a good work-around. I can keep my XML tidy and truly human-readable like that. (But I seriously doubt that it's good practice to put custom elements in the TEI namespace. Oh well, as long as nobody sees it ...)