Suppress default attributes in XML result of an XSLT
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 6
- Joined: Sun Dec 28, 2008 3:38 pm
Suppress default attributes in XML result of an XSLT
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:
transforms an original
into
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?
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>
Code: Select all
<div n="1">
Code: Select all
<div type="chapter" n="1" org="uniform" sample="complete" part="N">
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?
-
- Posts: 6
- Joined: Sun Dec 28, 2008 3:38 pm
about the XML source ...
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!
Any ideas on how to get rid of the default attrs in a sensible way? Thanks!
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Suppress default attributes in XML result of an XSLT
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
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
George Cristian Bina
-
- Posts: 6
- Joined: Sun Dec 28, 2008 3:38 pm
Re: Suppress default attributes in XML result of an XSLT
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 ...
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 ...
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Suppress default attributes in XML result of an XSLT
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
Regards,
George
George Cristian Bina
-
- Posts: 6
- Joined: Sun Dec 28, 2008 3:38 pm
leave namespace unspecified if unambiguous?
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 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 Is it possible somehow to leave the namespace unspecified if it is unambiguous anyway (Note that it works like that with DTD!)?
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>
Code: Select all
<myns:ved>
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Suppress default attributes in XML result of an XSLT
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
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
George Cristian Bina
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
Re: Suppress default attributes in XML result of an XSLT
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
Regards,
George
George Cristian Bina
-
- Posts: 6
- Joined: Sun Dec 28, 2008 3:38 pm
Re: Suppress default attributes in XML result of an XSLT
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 ...)
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 ...)
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service