Sorting elements by the value of @n
Oxygen general issues.
-
- Posts: 3
- Joined: Tue Oct 19, 2021 5:53 pm
Sorting elements by the value of @n
We are trying to develop an action in Java to sort elements by the value of their attribute n. Is there a simple way to do this?
The xml structure is as follows. Here the <msItemStruct> elements have a n attribute, but they are not sorted correctly. We would like to find a simple way to sort the elements according to the value of n.
Thanks in advance.
Michela
The xml structure is as follows. Here the <msItemStruct> elements have a n attribute, but they are not sorted correctly. We would like to find a simple way to sort the elements according to the value of n.
Code: Select all
<msItemStruct xml:id="handschriftID-msItemStruct-medieval">
<msItemStruct n="2">
<title xml:lang="lat">Decretum</title>
</msItemStruct>
<msItemStruct n="3">
<title xml:lang="lat">Brief Isidors von Sevilla an Bischof Massona von Mérida</title>
</msItemStruct>
<msItemStruct n="1">
<title xml:lang="lat">Ordo de celebrando concilio</title>
</msItemStruct>
</msItemStruct>
Michela
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Sorting elements by the value of @n
Hi Michela,
If you want to avoid using Java code:
If you are editing the XML document in the Author visual editing mode, you can customize in the Oxygen Preferences->"Document Type Association" page the framework you are using to edit the XML content, add a custom Author action based on an XSLT operation:
https://www.oxygenxml.com/doc/ug-editor ... yoperation
And the XSLT operation could invoke a script like this:
.
If you are editing the XML content in the Text editing mode or want to fix all places where the problem might appear in the XML content you could create a custom XML refactoring script based on XSLT to fix all such places in the entire XML document:
https://www.oxygenxml.com/doc/ug-editor ... tools.html
Regards,
Radu
If you want to avoid using Java code:
If you are editing the XML document in the Author visual editing mode, you can customize in the Oxygen Preferences->"Document Type Association" page the framework you are using to edit the XML content, add a custom Author action based on an XSLT operation:
https://www.oxygenxml.com/doc/ug-editor ... yoperation
And the XSLT operation could invoke a script like this:
Code: Select all
<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:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*:msItemStruct">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:for-each select="*:msItemStruct">
<xsl:sort select="xs:integer(@n)"/>
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
If you are editing the XML content in the Text editing mode or want to fix all places where the problem might appear in the XML content you could create a custom XML refactoring script based on XSLT to fix all such places in the entire XML document:
https://www.oxygenxml.com/doc/ug-editor ... tools.html
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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