 |
|
|
 |
| April 2001 |
 |
| DeveloperNet University Course |
 |
 |
Lab 6: Programming Input/Output Stylesheets
Learning Objective
In order for this lab to work, you must have already added the Publisher shim modify functionality from Lab 4 to your driver.
After performing this lab, you should be able to install an Input Transformation Rule stylesheet into your driver's publisher side so that it can convert the hyphen delimited phone numbers to dot delimited phone numbers during object add operations. You should also be able to program the input stylesheet so that it will perform the same conversion for object modify operations.
EXPLANATION: You may have noticed when entering a phone number in PBXSimulator, that it will only allow hyphens as delimiters.
Create an account in PBXSimulator. Notice when entering the phone number in PBXSimulator, that it will only allow hyphens as delimiters.
Commit the account to NDS. Notice that the phone number that is stored in NDS is delimited by hyphens, just as it was created in PBXSimulator.
This lab will have you install an input stylesheet that will transform the hyphen delimiters to dot delimiters for object add operations.
Then, the lab will have you add to the XSLT code in the stylesheet so that it also performs the transformation with modify operations.
Note: Read the Interpreting XPath section for more information about resolving XPath expressions.
Do This
- A working lab driver whose publisher shim has modify functionality is required for this lab. Refer to the procedures in Lab 1 if necessary to help you install and configure a lab driver. Then, refer to Lab 4 to implement publisher shim object modify functionality. Once you get the LabDriver working, shut it down.
EXPLANATION: During this lab, you will change the functionality in the driver by adding an input stylesheet. It is necessary to shut down the driver so that the stylesheet can be read when the driver is started back up again.
- Add an input stylesheet to your driver's publisher side so that, during object add operations, the publisher can convert PBXSimulator's hyphen delimited phone numbers to dot delimited phone numbers.
- Open the file, "C:\DirXMLCrsFldr\Lab1Driver\sources\rules\inputXform.xsl" in Notepad. It should look like the XSLT/XPath code shown below:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" >
<xsl:template match="child::node()|attribute::*"> <xsl:copy> <xsl:apply-templates select="child::node()|attribute::*"/> </xsl:copy> </xsl:template>
<xsl:template match="child::add-attr[attribute::attr-name='phone']/child::value"> <value type="teleNumber"> <xsl:value-of select="translate(child::text(),'-','.')"/> </value> </xsl:template>
</xsl:stylesheet>
- In ConsoleOne, select the Lab1Publisher object and create an input stylesheet object inside of it named "InputXform".
- In ConsoleOne, open InputXform's property book and display its "Edit XML" page under the "DirXML" tab.
- Copy the contents of "C:\DirXMLCrsFldr\Lab1Driver\sources\rules\inputXform.xsl" into the "Edit XML" window. Then, click "Apply" and close the property book.
- In ConsoleOne, open the Lab1Driver object's property book and display its "Other" page. Click the "Add" button on the page to add a "DirXML-InputTransform" attribute. Then browse to and select the newly created "InputXform" object to add its distinguished name as the attribute's value.
- View the transformation effects of the current input stylesheet.
EXPLANATION: If you set the DirXML-DriverSet object's "DirXML-XSLTraceLevel" attribute level to 4, the engine will display XDS documents for each stage of document processing. This can tell you what goes into your stylesheet and what comes out.
- To set up your driver to print XDS documents to DSTrace as they are processed by the rules and stylesheets, display the DirXML-DriverSet object's "Other" properties and add a new attribute: DirXML-XSLTraceLevel and set its value to 4.
- Start DSTrace and then start your driver.
- Create an account in PBXSimulator that has hyphens in its phone number and commit the account to NDS.
- Scroll down DSTrace to find a trace similar to the one shown below:
TRACE: Receiving DOM document from app XMLDrv:[11/22/00 13:36:38.01]: TRACE: <input> <add class-name="User" src-dn="0063"> <association>0063</association> <add-attr attr-name="firstName"> <value type="string">John</value> </add-attr> <add-attr attr-name="lastName"> <value type="string">Public</value> </add-attr> <add-attr attr-name="department"> <value type="string">engineering</value> </add-attr> <add-attr attr-name="location"> <value type="string">provo</value> </add-attr> <add-attr attr-name="phone"> <value type="teleNumber">222-333-4444</value> </add-attr> <add-attr attr-name="title"> <value type="string">every man</value> </add-attr> <add-attr attr-name="emplid"> <value type="string">0063</value> </add-attr> <add-attr attr-name="CN"> <value type="string">John Public</value> </add-attr> </add> </input> XMLDrv:[11/22/00 13:36:38.01]: TRACE: Applying input transformations XMLDrv:[11/22/00 13:36:38.01]: TRACE: Applying input stylesheet XMLDrv:[11/22/00 13:36:38.04]: TRACE: Input stylesheet returned: XMLDrv:[11/22/00 13:36:38.05]: TRACE: <input> <add class-name="User" src-dn="0063"> <association>0063</association> <add-attr attr-name="firstName"> <value type="string">John</value> </add-attr> <add-attr attr-name="lastName"> <value type="string">Public</value> </add-attr> <add-attr attr-name="department"> <value type="string">engineering</value> </add-attr> <add-attr attr-name="location"> <value type="string">provo</value> </add-attr>
<add-attr attr-name="phone"> <value type="teleNumber">222.333.4444</value> </add-attr> <add-attr attr-name="title"> <value type="string">every man</value> </add-attr> <add-attr attr-name="emplid"> <value type="string">0063</value> </add-attr> <add-attr attr-name="CN"> <value type="string">John Public</value> </add-attr> </add> </input>
EXPLANATION: Notice that the "phone" attribute in the Publication shim's output document (the input document to the stylesheet) contains hyphens.
Notice that the input stylesheet's "phone" output value contains dots. This change is a result of the transformation performed by the input stylesheet.
Refer to the previous XSLT/XPath explanation and the "InputXform" stylesheet to figure out for yourself why the translation was successful for the add operation.
When you are finished, compare your conclusions with the XSLT Solution Explanation 1.
- Edit the PBXSimulator account's "Phone Number" field and click "Commit" to send the new value to NDS. Then scroll through DSTrace to find a trace similar to the following:
XMLDrv:[11/22/00 14:31:41.09]: TRACE:Receiving DOM document from app XMLDrv:[11/22/00 14:31:41.09]: TRACE: <input> <modify class-name="User" src-dn="0063"> <association>0063</association> <modify-attr attr-name="phone"> <remove-all-values/> <add-value> <value type="teleNumber">333-333-3333</value> </add-value> </modify-attr> </modify> </input> XMLDrv:[11/22/00 14:31:41.10]: TRACE: Applying input transformationsXMLDrv:[11/22/00 14:31:41.10]: TRACE: Applying input stylesheetXMLDrv:[11/22/00 14:31:41.10]: TRACE: Input stylesheet returned:XMLDrv:[11/22/00 14:31:41.11]: TRACE: <input> <modify class-name="User" src-dn="0063"> <association>0063</association> <modify-attr attr-name="phone"> <remove-all-values/> <add-value> <value type="teleNumber">333-333-3333</value> </add-value> </modify-attr> </modify> </input>
Notice that the stylesheet failed to replace the hyphens in the "phone" attribute value with dots for the modify operation.
This is because the stylesheet is matching on an <add-attr> element but not a <modify-attr> element.
- Add code to the input stylesheet so that it will also translate the delimiters during modify operations.
Add another match element or modify one of the existing match elements in the "InputXform" stylesheet so that it will translate "phone" values from PBXSimulator for modify operations as well as add operations.
Hint: You would probably want to translate any <value> attribute whose "type" attribute has a value of "teleNumber". That being the case, why not match that <value> element. The resulting template would then translate phone delimiters for any kind of operation.
Copy your InputXfrom.xsl changes into the Lab1Publisher InputXform object as above. You must restart your driver for your changes to take effect.
When you are finished, compare your solution with that described in XSLT Solution Explanation 2.
|