Convert elements to attributes
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 1
- Joined: Sun May 15, 2016 11:09 pm
Convert elements to attributes
Hello,
I am fairly new to oxygen. I now have received a file without a schema and plenty of other oddities.
I'd like to change it a bit to begin with. Can't figure out how to change the structure from:
to
Any help is much appreciated!
Thanks
b
I am fairly new to oxygen. I now have received a file without a schema and plenty of other oddities.
I'd like to change it a bit to begin with. Can't figure out how to change the structure from:
Code: Select all
<article>
<header>
<title></title>
<author></author>
<date></date>
</header>
<body>
<text>Überschrift des Artikels</text>
</body>
</article>
Code: Select all
<article title="" author="" date="">
<text> </text>
</article>
Thanks
b
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Convert elements to attributes
Hi.
Oxygen does not have a specialized operation for this.
You can use an XSL stylesheet that does this:
First part is a generic copy stylesheet (found in Oxygen/samples/xhtml/copy.xsl). The second part (Convert) addresses your specific situation, converts the elements from 'header' into attributes of the same name and copies the element from the 'body' element.
Regards,
Adrian
Oxygen does not have a specialized operation for this.
You can use an XSL stylesheet that does this:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<!-- Match document -->
<xsl:template match="/">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>
<!-- Deep copy template -->
<xsl:template match="*|text()|@*" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
<!-- Handle default matching -->
<xsl:template match="*"/>
<!-- Convert-->
<xsl:template match="article" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="convert-to-attr" select="header/*"/>
<xsl:apply-templates mode="copy" select="body/*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*" mode="convert-to-attr">
<xsl:attribute name="{name()}" select="text()"/>
</xsl:template>
</xsl:stylesheet>
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Convert elements to attributes
Create a transformation scenario in order to apply a stylesheet in Oxygen
To set up a transformation scenario, open the XML file and from the main menu invoke Document -> Transformation -> "Configure Transformation Scenario(s)" (there's a corresponding button in the toolbar)
In the "Configure Transformation Scenario(s)" dialog press "New" and select "XML transformation with XSLT" to create a new scenario:
1. Give it an appropriate name
2. Leave the "XML URL" field to its default(${currentFileURL})
3. In the XSL URL field browse for your stylesheet.
4. If you have an XSLT 2.0 stylesheet choose from the transformer combo Saxon-PE or Saxon-EE, otherwise you can leave it to Saxon6.5.5.
5. You can further tune the "Output". Please note that the "Save as" field must refer a single file, NOT an output directory. Use the editor variables to compose a generic name instead of a fixed one.
e.g in the "Save as" field you can specify: ${cfd}/${cfn}-out.xml which translates into <current-file-directory>/<current-filename>-out.xml
6. Press OK in the editing dialog and "Save and close".
7.To apply this transformation use : Document -> Transformation -> "Apply Transformation Scenario(s)" and the associated scenario will be used.
Regards,
Adrian
To set up a transformation scenario, open the XML file and from the main menu invoke Document -> Transformation -> "Configure Transformation Scenario(s)" (there's a corresponding button in the toolbar)
In the "Configure Transformation Scenario(s)" dialog press "New" and select "XML transformation with XSLT" to create a new scenario:
1. Give it an appropriate name
2. Leave the "XML URL" field to its default(${currentFileURL})
3. In the XSL URL field browse for your stylesheet.
4. If you have an XSLT 2.0 stylesheet choose from the transformer combo Saxon-PE or Saxon-EE, otherwise you can leave it to Saxon6.5.5.
5. You can further tune the "Output". Please note that the "Save as" field must refer a single file, NOT an output directory. Use the editor variables to compose a generic name instead of a fixed one.
e.g in the "Save as" field you can specify: ${cfd}/${cfn}-out.xml which translates into <current-file-directory>/<current-filename>-out.xml
6. Press OK in the editing dialog and "Save and close".
7.To apply this transformation use : Document -> Transformation -> "Apply Transformation Scenario(s)" and the associated scenario will be used.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
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