Protect An Element / Applying Value Using XSLT
Posted: Mon Apr 10, 2017 9:39 pm
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