Updating attribute based on element content
Post here questions and problems related to editing and publishing DITA content.
-
- Posts: 38
- Joined: Thu May 25, 2023 4:08 pm
Updating attribute based on element content
Hello there!
I have a specific use case, in which I must update the <title> element (regardless of the topic type, or if it's a section or a figure title) with whatever the <title> element contains.
For example:
The refactoring operation for this example would ideally result in the following:
This means that the <title> element would get an @id attribute with the value that consists of the content of the <title> element, preferably lowercase, with words separated by hyphens.
As an uneasy workaround, I can use the out-of-the-box Generate IDs operation with Elements: title and Value: ${cfn} (as our filenames are usually a match with the title), but I'm wondering if there's a more elegant solution to this.
Much appreciated,
Konrad
I have a specific use case, in which I must update the <title> element (regardless of the topic type, or if it's a section or a figure title) with whatever the <title> element contains.
For example:
Code: Select all
<task id="task-7cw1w0u6"><title>Task title</title>
Code: Select all
<task id="task-7cw1w0u6"><title id="task-title">Task title</title>
As an uneasy workaround, I can use the out-of-the-box Generate IDs operation with Elements: title and Value: ${cfn} (as our filenames are usually a match with the title), but I'm wondering if there's a more elegant solution to this.
Much appreciated,
Konrad
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Updating attribute based on element content
Hi,
I do not quite understand the use case, when people insert links, the links are to the elements which have the title element, for example you have a link to the <task> element and automatically the link text shows the title of the task element. Or add a link to a <section> and the title of the section is presented on the link text when publishing.
So why link directly to a title element?
Also once the value of an ID attribute changes, you may end up with broken links in the places where that ID was referenced.
Do you want to make such changes/updated in an entire project or only in the current file on specific elements?
Regards,
Radu
I do not quite understand the use case, when people insert links, the links are to the elements which have the title element, for example you have a link to the <task> element and automatically the link text shows the title of the task element. Or add a link to a <section> and the title of the section is presented on the link text when publishing.
So why link directly to a title element?
Also once the value of an ID attribute changes, you may end up with broken links in the places where that ID was referenced.
Do you want to make such changes/updated in an entire project or only in the current file on specific elements?
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 38
- Joined: Thu May 25, 2023 4:08 pm
Re: Updating attribute based on element content
Hi Radu,
I admit the use case is quite awkward and peculiar, some more context:
The CCMS we're using has a mechanism for generating the URLs based on topic titles. However, when you use chunking (chunk="to-content"), the URLs to the chunked child articles aren't based on topic titles, but some non-descriptive pattern (ariaid-title). To make the URLs to such chunked child topics descriptive (i.e. based on their titles), there's this super awkward workaround that requires you to add the @id attribute to the <title> of a chunked child topic, with a value that you want the URL to have.
So if you want your URL to a chunked topic with the title "Testing configurations" to NOT be "www. example.com/ariaid-title15", and be "www.example.com/testing-configurations", your code must be the following:
CCMS being CCMS, there's no easy way to achieve that, so I hope to use Oxygen XML to mass update the <title> elements across our content.
Currently, the <title> elements across our content don't have any @id attributes, so no worries about breaking any references to these.
I admit the use case is quite awkward and peculiar, some more context:
The CCMS we're using has a mechanism for generating the URLs based on topic titles. However, when you use chunking (chunk="to-content"), the URLs to the chunked child articles aren't based on topic titles, but some non-descriptive pattern (ariaid-title). To make the URLs to such chunked child topics descriptive (i.e. based on their titles), there's this super awkward workaround that requires you to add the @id attribute to the <title> of a chunked child topic, with a value that you want the URL to have.
So if you want your URL to a chunked topic with the title "Testing configurations" to NOT be "www. example.com/ariaid-title15", and be "www.example.com/testing-configurations", your code must be the following:
Code: Select all
<task id="task-7cw1w0u6"><title id="testing-configurations>Testing configurations</title>
Currently, the <title> elements across our content don't have any @id attributes, so no worries about breaking any references to these.
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Updating attribute based on element content
Hi,
I think a custom XML refactoring action implemented in XSLT would help for this:
https://www.oxygenxml.com/doc/ug-editor ... tions.html
I created a sample refactoring action which does what you want here:
https://github.com/oxygenxml/dita-refac ... n%20Titles
So if you download this entire project:
https://codeload.github.com/oxygenxml/d ... ads/master
and in the Oxygen Preferences->"XML / XML Refactoring" page you add a link to the "47 Generate IDs on Titles" folder, then in the Oxygen main menu "Tools->XML refactor" dialog you should find the new action named "Set IDs on all Titles Based on Text".
If your content is on a remote CMS and you open the DITA Map in the DITA Maps Manager view, you can right click it and choose "Refactoring->XML Refactoring", as the content is on the CMS I cannot guarantee that saving all those modified files directly to the CMS will work, this depends on the CMS integration plugin in Oxygen.
Regards,
Radu
I think a custom XML refactoring action implemented in XSLT would help for this:
https://www.oxygenxml.com/doc/ug-editor ... tions.html
I created a sample refactoring action which does what you want here:
https://github.com/oxygenxml/dita-refac ... n%20Titles
So if you download this entire project:
https://codeload.github.com/oxygenxml/d ... ads/master
and in the Oxygen Preferences->"XML / XML Refactoring" page you add a link to the "47 Generate IDs on Titles" folder, then in the Oxygen main menu "Tools->XML refactor" dialog you should find the new action named "Set IDs on all Titles Based on Text".
If your content is on a remote CMS and you open the DITA Map in the DITA Maps Manager view, you can right click it and choose "Refactoring->XML Refactoring", as the content is on the CMS I cannot guarantee that saving all those modified files directly to the CMS will work, this depends on the CMS integration plugin in Oxygen.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 38
- Joined: Thu May 25, 2023 4:08 pm
Re: Updating attribute based on element content
Hi Radu,
Thank you very much! I updated the XSLT a bit to use hyphens as word separators and drop special characters in the id, but this has been a perfect starting point.
Great support, as always.
Kind regards,
Konrad
Thank you very much! I updated the XSLT a bit to use hyphens as word separators and drop special characters in the id, but this has been a perfect starting point.
Great support, as always.
Kind regards,
Konrad
Return to “DITA (Editing and Publishing DITA Content)”
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