cc/td/doc/product/webscale/cte1400/rel2_5
hometocprevnextglossaryfeedbacksearchhelp
PDF

Table of Contents

Applying Rules to Several Elements
Introduction
Applying Rules Based on Element Name or Text
Applying Rules Based on Depth
Applying Rules Based on Position
Applying Rules Based on Element Attribute Values
Applying the Move Rule to Several Elements
Applying the Dial Number Rule to Several Elements
Manually Configuring the XPath Expression of an Element

Applying Rules to Several Elements


The following sections describe how to apply rules to several elements:

Introduction

Rather than recreating the same rule for several elements on a page, you can create one rule and apply it to those elements. For example, if you want to change every hr element to a br element, you select the first br element, choose the Modify rule, and specify how you want the rule applied throughout the page. This feature simplifies the development and maintenance of configuration files and also results in more efficient operation for the CTE.

The Configure Rule dialog box for most rules contains a Path to Selected Element area, as shown in Figure 5-1. To apply a rule to more than one element on a page, you configure at least one of the elements in the list.


Figure 5-1   Path to Selected Element Area


The Path to Selected Element area lists every tag (enclosed in angle brackets) and text element that is in the path to the element to which you are applying a rule. The last item in the list is the tag or text element selected in the XHTML source view when you chose a rule. To apply a rule to several elements, you typically start by configuring the last path element in the list. In some cases, you must configure more than one path element to achieve the intended result.

If an element occurs more than once in the path to a selected element, the repetition is indicated by the icon
, as shown in Figure 5-2. When you want to apply a rule to several elements and see that an item in the element path is repeated, consider if configuring the repeated element will give you the intended results.


Figure 5-2   Repeated Element in the Path to Selected Element


After you select a tag or text in the Path to Selected Element area, the dialog box displays settings for configuring a path element (Figure 5-3) or a text element (Figure 5-4).


Figure 5-3   Configure Path Element



Figure 5-4   Configure Text Element


To expand the scope of a rule, you change the default settings. By default, a rule matches the tag name or text element and applies only to the selected element; attribute values are ignored.

Applying Rules Based on Element Name or Text

When you apply a rule, you typically match against the element name, such as form, or the element text. For example, when you select a form element to clip, you often want the clip rule to apply only to that form element and not to all elements. If you are applying a rule to text, you often want the rule to apply only to the selected text string.


Note   When applying rules to several elements, be aware that the Select rule always takes precedence and that the last rule added has the highest priority. If a previously added rule no longer takes effect, delete and reapply the rule.

Element Name

You typically choose to not match by element name only if the information you want to match is always at a particular position in the XHTML but is not associated with a particular element. For example, perhaps you want to match on a particular attribute rather than an element. To not match by element name, clear the Match Element Name option in the Configure Path Element dialog box.

For information on how to work with the interaction between the element name and position setting, see the "Applying Rules Based on Position" section.

You can choose to skip an element that is in the path to the element you are transforming. By skipping an element, you allow a rule to apply higher in the tree hierarchy. This might be necessary for dynamic content in which formatting elements (font, b) may or may not be present. Skipping an element is also useful for tables whose structure can vary.

Suppose that you are working with a document that includes the following dynamic content:

table
  tr
    td
     b
      Hello
 
  tr
    td
     b
      World
 

Assume that on the dynamically generated page, the b element may not be present around "Hello" and that you want to apply a rule to "Hello." By skipping the b element, you allow the rule to apply to "Hello" whether or not the b element is present. In addition to skipping the b element, you should also use the Any Descendant setting for the rule on the text element "Hello." Using the Any Descendant setting with the Skip This Element setting is typical usage.

To skip an element, perform these steps:


Step 1   In the XHTML source view, right-click the element on which you want to apply a rule.

Step 2   Choose the rule from the shortcut menu.

Step 3   In the Configure dialog box, click the element that may or may not appear in dynamically generated content.

Step 4   Click Skip This Element to select it.

In the following example, the small element is the optional element.


Step 5   In the Path to Selected Element area, click the last element listed (the element on which you are applying the rule).

Step 6   From the Depth to Match drop-down menu, choose Any Descendant.

The Any Descendant setting allows the element to be matched whether it is at its current depth or one depth higher.

Step 7   Change other settings in the Configure: Rule dialog box as needed and then click OK.



Element Text

To configure element text, you specify the text that an element must contain in order for the rule to apply to the element. By default, a rule applies only to text elements with the exact string. You can choose to apply a rule more broadly, such as to any text element that contains the original string. Table 5-1 describes the text to specify and menu item to select based on the text that you want to match (as a condition for applying a rule).

Table 5-1   Specifying Text to Match

Text to Match Against  Match Text Field  Operation Menu Setting 

Exact original text string

original text

Equals

Text strings that contain the original text

original text

Contains

Any text string

original text

Any Text

Exact modified text string

modified text

Equals

Text strings that contain the modified text

modified text

Contains

Text strings that do not equal the specified text string

variable text

Not Equal

Text strings that do not contain the specified text string

variable text

Not Contain

Text strings that start with the specified text string

variable text

Starts With

Applying Rules Based on Depth

Depth refers to how an element is nested along the x-axis in the XHTML. Suppose that a web page includes the following XHTML structure:

table
    table
        table
        table
  

The second table element is a descendent of the first table element. There are tables at three different depths.

Suppose that you want to use one rule to remove the borders from several tables. Your web page contains the following XHTML structure. The table element in bold and underlined is the element selected when you apply a command.

table
    table
        table
        table
    table
table
    table
table
  

Table 5-2 shows how each Depth to Match setting applies to other table elements, given the setup in this section. The elements affected by the depth settings are in bold and underlined in Table 5-2.

Table 5-2   Effect of XHTML Depth Settings

Exact  All Depths  Any Descendant 
table
    table
        table
        table
    table
table
    table
table
  

The CTE will apply the rule only to this table.

table
    table
        table
        table
    table
table
    table
table
  

The CTE will apply the rule to tables at all depths.

table
    table
        table
        table
    table
table
    table
table
  

The CTE will apply the rule to this table and its descendant table.

For more information, see the following sections:

Applying Rules Based on Position

Position refers to the sequence of a tag or text element along the y-axis in the XHTML. Suppose that a web page includes the following XHTML structure:

table
text element1
table
form
table
text element2
table
  

The four table elements are in positions one through four, provided you are matching on the element name table. If you are not matching on element name, all tag types are included in the count: The four table elements are in positions one, two, four, and five. The form element is in position three. Text elements are not included in the tag count; tags are not included in the text element count.

Suppose that you want to use one rule to clip several rows from all tables. Your web page contains the following XHTML structure. The table element in bold and underlined is the element selected when you apply a command.

table
    table
        table
        table
        form
        table
        table
    table
        table
        table
        table
  

Table 5-3 shows how each Position to Match setting applies to other table elements, given the setup in this section. Assume that the Match Element Name setting is selected and that the Depth to Match setting is Exact. The elements affected by the position settings are in bold and underlined in Table 5-3.

Table 5-3   Effect of Element Position Settings

Exact  Range (2-3)  All Positions 
table
    table
        table
        table
        form
        table
        table
    table
        table
        table
        table
  

The CTE will apply the rule only to this table.

table
    table
        table
        table
        form
        table
        table
    table
        table
        table
        table
  

The CTE will apply the rule only to the second and third tables at this depth.

To achieve the results shown, you may need to configure more than one path element.

table
    table
        table
        table
        form
        table
        table
    table
        table
        table
        table
  

The CTE will apply the rule to all tables at this depth.

To achieve the results shown, you may need to configure more than one path element.


Note   When applying rules to several elements, be aware that the Select rule always takes precedence and that the last rule added has the highest priority. If a previously added rule no longer takes effect, delete and reapply the rule.

For more information, see the following sections:

How the Depth and Position Settings Interact

The depth and position settings work together, providing you with precise control over how narrowly or broadly a rule is applied. Table 5-4 describes how to set the Depth to Match and the Position to Match options based on how you want to apply a rule.

Table 5-4   Choosing Depth and Position Options

To Apply a Rule to Depth to Match Setting Position to Match Setting

This exact element only

Exact

Exact

This position of the element at all depths

All Depths

Exact

This element and matching descendant elements

Any Descendant

Exact

This depth of the element at all positions

Exact

All Positions

Every occurrence of the element

All Depths

All Positions

All positions of this element and matching descendant elements

Any Descendant

All Positions

Several positions of this element at this depth

Exact

Range

Several positions of this element at all depths

All Depths

Range

Several positions of this element and matching descendant elements

Any Descendant

Range

Choosing depth and position settings that have your intended results may require some experimentation. If you are unsure how to achieve a particular result, test the position settings first, followed by the depth settings. If changing just a depth or position setting does not work, then try combinations of those settings.

Example: Applying a Rule to a Range of Positions

Consider the following scenario:

table
    a href="link"
        text element
    br
    [the above link/text/break pattern is repeated n times]
    table
        a href="link"
            text element
        br
    [the above link/text/break pattern is repeated n times]
  

To include all but the first two link/text/break combinations in each table, perform these steps to configure the a element and the br element:


Step 1   In the XHTML source view, right-click the first occurrence of the a element you want to clip.

Step 2   Choose Clip from the shortcut menu.

Step 3   In the Configure: Clip Rule dialog box, scroll to the end of the Path to Selected Element list and click the a element.

Step 4   Configure the a element as follows:

Match Element Name: selected
Depth to Match: All Depths
Position to Match: Range Min = 1 and Range Max = 2

Step 5   Click OK.

Step 6   In the XHTML source view, right-click the br element that immediately follows the a element you just worked with.

Step 7   Choose Clip from the shortcut menu.

Step 8   In the Configure: Clip Rule dialog box, scroll to the end of the Path to Selected Element list and click the br element.

Step 9   Configure the br element as follows:

Match Element Name: selected
Depth to Match: All Depths
Position to Match: Range Min = 1 and Range Max = 2

Step 10   Click OK.



Example: Applying a Rule to Several Nested Tables

Consider the following scenario:

table
    tr
        td
            table
            table
            table
        td
            table
            table
            table
  

To apply the Modify rule to the nested tables (which are contained in two columns), you must configure the table and td elements so that the rule will iterate across the columns.

To configure the table element and the td element, perform these steps:


Step 1   In the XHTML source view, right-click the first nested table element.

Step 2   Choose Modify from the shortcut menu.

Step 3   Click the Modify Element tab.

Step 4   Change the value of "border" to 0.

Step 5   Click the Configure Rule tab.

Step 6   Scroll to the end of the Path to Selected Element list and click the table element.

Step 7   Configure the table element as follows:

Match Element Name: selected
Depth to Match: Exact
Position to Match: All Positions

Step 8   Click OK.

In the browser view, the borders are removed only from the tables in the left-most column.

Step 9   In the XHTML source view, right-click the table element that has the Modify icon (
) and select Edit Rule from the shortcut menu.

Step 10   In the Path to Selected Element area, click the td element that immediately precedes the last table element.

Step 11   Configure the td element as follows:

Match Element Name: selected
Depth to Match: Exact
Position to Match: All Positions

Step 12   Click OK.

In the browser view, the borders are removed from the tables in both columns.



Applying Rules Based on Element Attribute Values

By default, the CTE ignores the values of element attributes. For example, if the CTE finds a form element at a specified depth and position, it applies a rule to the form regardless of attribute values. However, you might want to specify that a rule applies only to forms with a particular method or target attribute. In addition, when you create transformation rules for a page that is dynamically generated, you might not know at what depth or position an element resides. However, you might know that the table elements you want to apply the rule to always have a particular datasrc attribute.

Table 5-5 describes how to set the attributes area based on how you want to apply a rule. For an example, see the "Example: Applying a Rule to All Occurrences of an Element with a Specified Attribute" section.

Table 5-5   Changing How an Attribute is Matched

Value to Match Against  Task 

The exact value of an attribute

  • Click the Operation drop-down arrow for the attribute and choose Equals.

A portion of the value

  • Click the Operation drop-down arrow for the attribute and choose Contains.

A different value for an attribute

  • Select the value of the attribute and change it. Then, click the Operation drop-down arrow for the attribute and choose either Equals, Contains, Not Equal, or Not Contain.

An attribute with a value that starts with the specified text string

  • Select the value of the attribute and change it. Then, click the Operation drop-down arrow for the attribute and choose Starts With.

Example: Applying a Rule to All Occurrences of an Element with a Specified Attribute

Consider the following scenario:

To apply a rule to the form element regardless of its position on the page, configure the form element as follows:

Match Element Name: selected
Depth to Match: All Depths
Position to Match: All Positions
datasrc Attribute Operation: Equals

Applying the Move Rule to Several Elements

A Move rule contains path information for both the source element you are moving and its destination. When you create a Move rule, as described in the "Moving an Element Tag" section, the Configure: Move Rule dialog box shows the path that is common to the source element and its destination, followed by two folders named Source and Destination. The Source folder lists the path to the element you are moving. The Destination folder lists the path to the element where you are relocating the element as shown in Figure 5-5.


Figure 5-5   Path to Source and Destination Folders


You can apply the Move rule to several source elements and to several destinations. Suppose that you are working with a page that contains several input fields followed by a label and you want to move each label so that it displays in front of the input field. You can do that with one Move rule by applying the rule to several source and destination elements.

To move or copy several elements, perform these steps:


Step 1   In the Configure: Move Rule dialog box, click the Source tab.

The Source tab lists the full path to the element you selected to be moved.

Step 2   In the Path to Selected Element area, click the element you are moving.

Step 3   Specify how you want Design Studio to match the elements you want to move.

For example, if you are moving all a elements that appear in a table, click the first a element and then choose All Positions from the Position to Match drop-down menu.


Note    Design Studio does not allow you to change the depth setting of the first element listed for the Source. Because the depth of the first Source element is relative to the Destination Path, Design Studio must retain the depth setting of the element in order to track the XPath of the element.

Step 4   Click OK.



To move or copy to several locations, perform these steps:


Step 1   In the Configure: Move Rule dialog box, click the Destination tab.

Step 2   In the Path to Selected Element area, click the element before or after which you are moving the source element.

Step 3   Specify how you want Design Studio to match against several destination elements.

For example, if you are moving one or more source elements after several input elements, click the first input element and then choose the appropriate position and depth settings.

Step 4   Click OK.



Applying the Dial Number Rule to Several Elements

A Dial Number rule contains path information for both the dialable number and its label. When you create a Dial Number rule, as described in the "Adding a Dialable Phone Number" section, the Configure: Dial Number Rule dialog box includes the path to the phone number and label as shown in Figure 5-6.


Figure 5-6   Path to Phone Number and Label


You can apply the Dial Number rule to several phone numbers and labels. Suppose that you want to make all numbers in a directory listing dialable. You can do that with one Dial Number rule by applying the rule to several pairs of phone numbers and label elements.

To apply the Dial Number rule to several phone numbers, perform these steps:


Step 1   In the Path to Selected Element area, click the phone number you want to be dialable.

Step 2   Specify how you want Design Studio to match other phone numbers you want to be dialable.

For example, if all phone numbers you want to be dialable have a common prefix, such as "(800)", choose Starts With from the Operation drop-down menu, change Match Text to "(800)", and choose All Positions from the Position to Match drop-down menu, as shown in the following example.


Step 3   Click OK.



To apply the Dial Number rule to the label for each dialable phone number, perform these steps:


Step 1   In the Configure: Dial Number Rule dialog box, click the Label tab.


Note    This procedure assumes that you have already specified a label for the Dial Number rule when you created it. For more information, see the "Adding a Dialable Phone Number" section.

The Label tab lists the path to the element you selected for the label.

Step 2   In the Path to Selected Element area, click the text you chose for the label.

Step 3   Specify how you want Design Studio to match other labels.

Step 4   Click OK.



Manually Configuring the XPath Expression of an Element


Note   This feature is intended only for users familiar with XSL.

You can manually configure an element by editing its XPath expression. This feature provides more flexibility in node selection when applying a rule.You can modify an XPath expression to address one or several nodes.

Table 5-6 contains the XPath expression to use to achieve various results.

Table 5-6   XPath Expression Examples

Intended Selection  XPath Expression 

All elements that are not tables (use, for example, to delete everything but the tables)

*[not(self::table)]

Last row (tr element) in a table

tr[position() = last()] 

All rows except the last row of a table

tr[position()>=1 and position()<=last()-1] 

Every other tr element after the third row

tr[position()> 3 and position() mod 2 = 0]

The third row that has the class attribute

tr[@class][position()=3] 
tr[@class][3] 

The third row that has the class attribute set to specialrow

tr[@class='specialrow'][position()=3] 
tr[@class='specialrow'][3] 

The third row only if it has the class attribute set to specialrow

tr[position()=3][@class='specialrow'] 
tr[3][@class='specialrow'] 

The rows that do not have the class attribute

tr[not(@class)]

The first text element only if it equals "Howdy"1

text()[1][self::text()='Howdy'] 

The first "Howdy" text element

text()[self::text()='Howdy'][1] 

The first text element only if it equals the contents of the text field in the dialog box

text()[1][self::text()=$a4868257202001]
If the text you want to configure contains special characters, particularly single or double quotation marks, be sure to enter the text in the text field and click Reload to retrieve the XPath expression provided by Design Studio. You must include any text variables provided by Design Studio in your XPath expression.

For more information about XPath pattern matching, see http://www.w3.org/TR/xpath.

To manually configure an XPath expression, perform these steps:


Step 1   In the Configure Rule dialog box, set the depth and position options.

Step 2   Click Manually Configure Element to select it.

Step 3   Click Reload to view the current XPath expression for the node.

Step 4   Edit the XPath configuration in the text box.


Design Studio alerts you if you enter invalid syntax for the XPath.

Step 5   Click OK.




hometocprevnextglossaryfeedbacksearchhelp
Posted: Mon Aug 18 16:34:47 PDT 2003
All contents are Copyright © 1992--2003 Cisco Systems, Inc. All rights reserved.
Important Notices and Privacy Statement.