Protect An Element / Applying Value Using XSLT
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 32
- Joined: Mon Apr 10, 2017 8:56 pm
Protect An Element / Applying Value Using XSLT
Hello,
I am working on a desired feature for an XML document that will be authored using Oxygen XML Web Author.
The XML document has <title> elements - and each <title> has an optional hardTitle attribute. If hardTitle is populated, the element content should reflect the attribute value. If hardTitle is not populated, the title can be whatever the author wants.
Example:
Currently, I have an XSL file/transformation scenario that will apply the value of hardTitle to the element value. However, the update has to be run manually (instead of an on-change action) - and it requires a new file be created to hold the changes.
Ideally, I would like any <title> with a populated hardTitle attribute to act as if it were protected (the user's can't edit it even if they try). I was trying to implement it so that:
1.) On element exit, the transform would run
2.) The transformed document (with the correct title) would reload in the editor window
This would have the effect of not allowing users to change the title.
Of course, I am open to any other ways of implementing this desired behavior. Any suggestions would be greatly appreciated!
Thanks!
John
I am working on a desired feature for an XML document that will be authored using Oxygen XML Web Author.
The XML document has <title> elements - and each <title> has an optional hardTitle attribute. If hardTitle is populated, the element content should reflect the attribute value. If hardTitle is not populated, the title can be whatever the author wants.
Example:
Code: Select all
<chapter>
<title hardTitle="Scope of Effort">Scope of Effort</title>
</chapter>
<chapter>
<title>Any Title</title>
</chapter>
Code: Select all
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>
<xsl:template match="title[@hardTitle]">
<xsl:copy>
<!-- supposes that <title> elements will not have child elements -->
<xsl:apply-templates select="@*" />
<xsl:value-of select="@hardTitle" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
1.) On element exit, the transform would run
2.) The transformed document (with the correct title) would reload in the editor window
This would have the effect of not allowing users to change the title.
Of course, I am open to any other ways of implementing this desired behavior. Any suggestions would be greatly appreciated!
Thanks!
John
-
- Posts: 517
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Protect An Element / Applying Value Using XSLT
Post by cristi_talau »
Hello,
You can create a better user experience by tweaking the CSS used for rendering. For example:
You can also register an AuthorDocumentFilter [1] that will update the content of the title whenever the "hardTitle" attribute is changed. Or even more, reject any updates on the "hardTitle" attribute.
Best,
Cristian
[1] https://www.oxygenxml.com/InstData/Edit ... ilter.html
You can create a better user experience by tweaking the CSS used for rendering. For example:
Code: Select all
// if the title element has a "hardTitle" attribute
title[hardTitle] {
-oxy-editable: false; // The content of the title will not be editable
visibility: -oxy-collapse-text; // The text content of the title will not be rendered
content: attr(hardTitle); // Instead, render the value of the "hardTitle" attribute
}
Best,
Cristian
[1] https://www.oxygenxml.com/InstData/Edit ... ilter.html
-
- Posts: 32
- Joined: Mon Apr 10, 2017 8:56 pm
Re: Protect An Element / Applying Value Using XSLT
Hi Christian!
Thank you so much for the help. Your css suggestion providee the exact desired behavior.
Now I have a follow-up question though. When the user tries to modify a <title> that has a hardTitle, they get the following error message:
Insert text failedThe selection has an endpoint inside an invisible range: 646
I would like to change the error message to something along the lines of:
[hardTitleValue] is a required title or, if it simplifies things, This title is required and cannot be changed.
Is there a way to customize the message? I found the following forum entry - but I'm not using reference revolvers.
post36611.html?hilit=customize%20error%20message#p36611
Any suggestions would be greatly appreciated!
Thanks!
John
Thank you so much for the help. Your css suggestion providee the exact desired behavior.
Now I have a follow-up question though. When the user tries to modify a <title> that has a hardTitle, they get the following error message:
Insert text failedThe selection has an endpoint inside an invisible range: 646
I would like to change the error message to something along the lines of:
[hardTitleValue] is a required title or, if it simplifies things, This title is required and cannot be changed.
Is there a way to customize the message? I found the following forum entry - but I'm not using reference revolvers.
post36611.html?hilit=customize%20error%20message#p36611
Any suggestions would be greatly appreciated!
Thanks!
John
-
- Posts: 517
- Joined: Thu Sep 04, 2014 4:22 pm
Re: Protect An Element / Applying Value Using XSLT
Post by cristi_talau »
Hello,
You can try the AuthorDocumentFilter Java extension that I mentioned in a previous post. That way you can block the character insertion and provide a custom error message using AuthorAccess#showErrorMessage() [1].
Best,
Cristian
[1] https://www.oxygenxml.com/InstData/Edit ... ccess.html
You can try the AuthorDocumentFilter Java extension that I mentioned in a previous post. That way you can block the character insertion and provide a custom error message using AuthorAccess#showErrorMessage() [1].
Best,
Cristian
[1] https://www.oxygenxml.com/InstData/Edit ... ccess.html
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