XMetaL Tips and Tricks
Derek Read November 27, 2008 at 11:48 pm
Script Example: Change Text Case FunctionsNovember 27, 2008 at 11:48 pmParticipants 5Replies 6Last Activity 14 years, 2 months ago
Tested with XMetaL Author Enterprise 5.1.1.017
Macros for changing the case of text for the selected portion of a document.
Includes the Following Functions:
- Sentence case
- tOGGLE cASE
The operation of these functions is similar to those provided with popular word processors (ie: like MS Word, Open Office, etc) though they function in an XML context. We are dealing with XML so these scripts should not invalidate the document. They are primarily meant to change the case for PCDATA content, not elements (tags), attributes, or attribute values. In some cases they can be used to change the case of COMMENTS, CDATA sections and Processing Instructions. In this case you need to select a portion of these types of markup rather than the entire COMMENT, CDATA or PI node.
* Licensed Materials – Property of JustSystems, Canada, Inc.
* (c) Copyright JustSystems Canada, Inc. 2008
* All rights reserved.
* The sample contained herein is provided to you “AS IS”.
* It is furnished by JustSystems Corporation as a simple example and has not been
* thoroughly tested under all conditions. JustSystems Canada, Inc., therefore, cannot
* guarantee its reliability, serviceability or functionality.
* This sample may include the names of individuals, companies, brands and products
* in order to illustrate concepts as completely as possible. All of these names are
* fictitious and any similarity to the names and addresses used by actual persons or
* business enterprises is entirely coincidental.
Script Installation and Usage:
Important: This script is being made available for use by experienced users, administrators and/or IT departments (people that manage the installation and configuration of an XMetaL deployment). Test this script in a test environment (non-production machine) before distributing to end users. This is unsupported demo code.
1. Download changeTextCaseFunctions.zip.
2. Unzip the file to an empty folder of your choice.
3. Examine the code contained in the MCR file and integrate it into your XMetaL Author or XMAX customization. The MCR file has been written so that it may simply be dropped into the
Startup folder to provide this functionality to all DTDs and Schemas (it is an Application-level macro). The code contains detailed comments inline that explain the logic. The comments also include information on known limitations and the rationale for not attempting to resolve them. It is assumed that these limitations will not affect the vast majority of users but if you have time to resolve them please share any improvements here.
4. Test all the functions on test documents that are as similar to what your end users will be working with before using them in production. You should be able to undo the changes each of the functions makes to a document using XMetaL Author's Undo operation.
Some Use Cases:
- Document has a
element containing some words that do not begin with a capital letter. User selects the entire element, selects the function “Change Case: Capitalize”. The function capitalizes the first letter in each word in the title.
- Document has one or more words in lowercase that should be in uppercase. User selects the word(s), selects the function “Change Case: UPPERCASE”. The function changes all the letters in each selected word to uppercase.
- Ditto (but opposite) for “Change Case: lowercase”.
- The document has a
element containing a number of sentences, not all of which begin with a capital. User selects the entire element, selects the function “Change Case: Sentence case”. The function capitalizes the first letter in the selection and every letter immediately following the sequence “. ” (period+space). All other letters are made lowercase.
- The “Change Case: tOGGLE cASE” function is (I assume) seldomly used, but most other products have it. This function simply changes uppercase letters to lowercase and vice versa.
- The document has a lot of code (example: C++, J#, C#, VB, etc) inside a CDATA section that should be changed. User selects just a portion of the CDATA section (also applies to COMMENT and PIs) avoiding the opening and closing markup, then runs one of the functions to change the selected text. Double clicking to select a word may be useful in this case, as is the mouse sequence: double click to select a word, keep mouse button down and immediately drag to extend the selection as well as the shift + mouse click combination. Note that one of the limitations of this script occurs when it encounters an unescaped “>” character inside CDATA, COMMENT or PI. See the comments in the MCR file.
Most of these scripts should function with XMetaL Author versions 2.0 and up, except for the event On_Application_Document_Context_Menu, which was introduced in the 5.0 releases. If your version of XMetaL Author does not have this event you can probably change it to On_Context_Menu and integrate all the scripts into a document-level customization instead. That has not been tested.dcramer December 2, 2008 at 6:30 am
Reply to: Script Example: Change Text Case FunctionsDecember 2, 2008 at 6:30 am
Works in 4.6 (moving the context menu stuff to On_Context_Menu).
Davidlav25 December 2, 2008 at 10:22 am
Reply to: Script Example: Change Text Case FunctionsDecember 2, 2008 at 10:22 am
Lovely feature. I've been after this for a long time!
Quick tests in 5.1 worked.dcramer January 11, 2010 at 4:13 pm
Reply to: Script Example: Change Text Case FunctionsJanuary 11, 2010 at 4:13 pm
One small point: the functions don't work in file entities because it tried to validate the file and says the file is invalid if it doesn't have a doctype. I removed &&(ActiveDocument.IsValid == true) to get around this. It would be nice if you could do ActiveDocument.IsWellFormed instead (perhaps you can…guess I should check that).
DavidShaylesh December 30, 2015 at 9:34 am
Reply to: Script Example: Change Text Case FunctionsDecember 30, 2015 at 9:34 am
Can I create keyboard shortcuts for each of the change case functions? When I select any of these macros in the Macros dialog, the shortcut key settings in the dialog box are disabled.
Btw, I am using XMetal 6.Derek Read January 8, 2016 at 7:49 pm
Reply to: Script Example: Change Text Case FunctionsJanuary 8, 2016 at 7:49 pm
If you can't alter the keys using the dialog it is probably because you do not have write permissions to the Program Files folder (which is normal for all versions of Windows since XP SP3). You'll have to manually modify the file (probably by copying it elsewhere, editing it then copying it back). Assign the value key=”name” (with the appropriate key name) to each
in the MCR file.
The easier solution would be to upgrade to version 10 as it includes this feature as built-in functionality. In version 10 you can press Ctrl+F3 to change between the 5 types of casing for the currently selected text. You can also select text and use the context menu's “Text Case” option to select one of the five options.
In the documentation for version 10 this feature is called the “Text case assistant”.Derek Read March 10, 2016 at 1:07 am
Reply to: Script Example: Change Text Case FunctionsMarch 10, 2016 at 1:07 am
This feature has been added as built-in functionality starting with XMetaL Author Essential and XMetaL Author Enterprise 10.
Refer to the Help under the topic “Text case assistant” for full details.
1. Select text and press Ctrl+F3 repeatedly until you see what you want, or…
2. Select text, right click and select the “Text Case” submenu, then select one of 5 options, or…
3. Enable buttons for the 5 possible text case options on the Formatting toolbar (see Help topic above for details).
- You must be logged in to reply to this topic.