Using oxy_replace() Function and Xpath to replace Uppercase
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 5
- Joined: Tue Feb 18, 2020 5:29 pm
Using oxy_replace() Function and Xpath to replace Uppercase
Hello
Is it possible to use a combination of the oxy_replace() Function and xPath to find and replace elements with lower case versions of themselves??
oxy_replace ( text , target , replacement )
text:
The text in which the replace will occur. In my example this is the xPath to each "label".
target:
The target string to be replaced. In my example this is the @title attribute, currently in UPPER CASE.
replacement:
The string replacement. In my example this is the @title attribute, in the desired lower case
Is it possible to use a combination of the oxy_replace() Function and xPath to find and replace elements with lower case versions of themselves??
oxy_replace ( text , target , replacement )
text:
The text in which the replace will occur. In my example this is the xPath to each "label".
target:
The target string to be replaced. In my example this is the @title attribute, currently in UPPER CASE.
replacement:
The string replacement. In my example this is the @title attribute, in the desired lower case
-
- Posts: 9421
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Using oxy_replace() Function and Xpath to replace Uppercase
Hi,
Here is a sample XML document:
and CSS:
The CSS code demonstrates how you can have various CSS functions nest in each other.
Regards,
Radu
Here is a sample XML document:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="test.css"?>
<root>
<label id="labelID">some content TITLE after</label>
<element title="TITLE" idref="labelID"/>
</root>
Code: Select all
* {
display:block;
}
element:before {
content: oxy_replace(oxy_xpath(oxy_concat('//label[@id="', attr(idref), '"]/text()')), attr(title), oxy_lowercase(attr(title)));
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 78
- Joined: Wed Jun 22, 2016 2:48 pm
Re: Using oxy_replace() Function and Xpath to replace Uppercase
Post by adrian_sorop »
Hello,
To change the values of the attributes a Custom XML Refactoring action can be used.
The XML Refactoring Operation Descriptor is:
The XSLT script is:
Save the the descriptor(lowercase-attribute-value.xml) and the xslt script (lowercase-attribute-value.xsl) in a directory from your local drive and then refer the folder in Preferences->"XML / XML Refactoring" Load additional refactoring operations from field.
Regards,
Adrian S
To change the values of the attributes a Custom XML Refactoring action can be used.
The XML Refactoring Operation Descriptor is:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<refactoringOperationDescriptor
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.oxygenxml.com/ns/xmlRefactoring"
id="lower-case-attribute-value"
name="Lower case attribute value">
<description>Lower case the attribute value</description>
<script type="XSLT" href="lowercase-attribute-value.xsl"/>
<category>Attributes</category>
<parameters>
<description>Lowercase the value of the attributes</description>
<attributeLocation name="attribute_xpath" useCurrentContext="true">
<element label="Element">
<description></description>
</element>
<attribute label="Attribute">
<description/>
</attribute>
</attributeLocation>
</parameters>
</refactoringOperationDescriptor>
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"
xmlns:xr="http://www.oxygenxml.com/ns/xmlRefactoring" version="3.0">
<!-- The XPath that identifies the attributes -->
<xsl:param name="attribute_xpath" as="xs:string" required="yes"/>
<xsl:variable name="attributes" as="attribute()*">
<xsl:evaluate xpath="$attribute_xpath" as="attribute()*" context-item="/"/>
</xsl:variable>
<!-- A sequence with the local name of the attributes-->
<xsl:variable name="aln" select="distinct-values($attributes/local-name())"/>
<xsl:template match="/|*">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<!-- Update the attribute value -->
<xsl:template match="@*[local-name()= $aln]">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="lower-case(.)"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="text() | comment() | processing-instruction() | @*">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
Regards,
Adrian S
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
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