Discussion:
[oXygen-user] Find and replace with lowercase
Yudong Chen
2013-07-11 08:48:10 UTC
Permalink
Hello, everyone,

I was trying to find and change some attribute values to lowercase in hundreds of xml files, using the Find and Replace feature of Oxygen, but without success.

For example, there are many values reading like this (just example):

<mediaobject>
<imageobject>
<imagedata fileref="../images/AbcdEfg.png" width=".81cm"/>
</imageobject>
</mediaobject>

I succeeded in finding all of those values using regular expression but I don't know how to replace them with their lowercase versions.

Have you ever succeeded in doing the same thing? Would you please share the way you did it? Or it is just impossible with Oxygen?

Thanks,

Yudong
Oxygen XML Editor Support
2013-07-11 10:05:12 UTC
Permalink
Hello,

Unfortunately that's not possible with the Find/Replace tool from
Oxygen. It only supports Java regular expressions which do not have the
ability to lowercase/uppercase (as opposed to Perl 5 regular expressions).

Alternative solutions:
1. (for less then a hundred matches) Use "Find All" to obtain a list
with all matches and then manually navigate them (Ctrl+Shift+] /
Ctrl+Shift+[) and for each match use the Document > Source > To Lower
Case action. You can assign a shortcut to this action in Options > Menu
Shortcut Keys (search in the filter for 'to lower').

2. (for a hundred or more) Use an XSLT stylesheet that processes the XML
and lowercases the values of those attributes @fileref).
e.g.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<!-- Match document -->
<xsl:template match="/">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>

<xsl:template
match="@fileref[parent::*:imagedata/parent::*:imageobject/parent::*:mediaobject]"
mode="copy">
<xsl:attribute name="fileref" select="lower-case(.)"/>
</xsl:template>
<!-- Deep copy template -->
<xsl:template match="node()|text()|@*" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
<!-- Handle default matching -->
<xsl:template match="*"/>
</xsl:stylesheet>
This will remove the DOCTYPE if any, so you'll have to manually put it back.
Also note that by default a transformation expands the attribute
defaults (from the DTD/schema). You can disable that in the 'Advanced
options' (cogwheel button) of the Saxon 9 transformer when configuring
the transformation scenario.

Regards,
Adrian

Adrian Buza
oXygen XML Editor and Author Support

Tel: +1-650-352-1250 ext.202
Fax: +40-251-461482
***@oxygenxml.com
http://www.oxygenxml.com
Post by Yudong Chen
Hello, everyone,
I was trying to find and change some attribute values to lowercase in
hundreds of xml files, using the Find and Replace feature of Oxygen,
but without success.
<mediaobject>
<imageobject>
<imagedatafileref="../images/AbcdEfg.png"width=".81cm"/>
</imageobject>
</mediaobject>
I succeeded in finding all of those values using regular expression
but I don't know how to replace them with their lowercase versions.
Have you ever succeeded in doing the same thing? Would you please
share the way you did it? Or it is just impossible with Oxygen?
Thanks,
Yudong
_______________________________________________
oXygen-user mailing list
http://www.oxygenxml.com/mailman/listinfo/oxygen-user
David Cramer
2013-07-11 11:14:39 UTC
Permalink
Post by Oxygen XML Editor Support
This will remove the DOCTYPE if any, so you'll have to manually put it back.
Also note that by default a transformation expands the attribute
defaults (from the DTD/schema). You can disable that in the 'Advanced
options' (cogwheel button) of the Saxon 9 transformer when configuring
the transformation scenario.
If you're processing a doc with a DOCTYPE, the following thread includes
a python script that cloaks entities and restores the DOCTYPE:
https://lists.oasis-open.org/archives/docbook/201304/msg00046.html

In this case, however, it might just be easier to use sed on the xml
file to lowercase the file names to begin with.

David

Loading...