Tested with XMetaL Author Enterprise 5.1.1.017Script Example:
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.Legal:
* 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 <xmetal author install path>\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 <title> 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 <p> 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.