The Custom XSL Web capture option allows developers to create an XSL file that can be used to transform HTML from the target Web site to XML using jTidy.
When selecting Custom XSL as a strategy, a View button appears that allows users to view the “tidied” HTML that will be presented to the XSL. This HTML (which is actually XML, after jTidy has processed it) is then shown in a pop-up window, using IE's standard XML browser. Using this window it is possible to expand/collapse XML nodes and traverse the complete XML (HTML) tree returned. This will make creating the XSL required to map this to an appropriate output easier.
Plenty of resources exist on the Web for writing XSL. Keep in mind the following guidelines:
The XSL can be used to create either XML or HTML. If it creates XML, then the XML must conform to the basic “Onepage XML” format:
Sequential <Record>
tags,
each containing a sequence of <Field>
tags.
Each <Record>
tag
must contain the same number of <Field>
tags.
The <Record>
tags
must be enclosed in a single tag <data>
.
If the output is in this form, then the output
must contain an XML comment <!-- onepage_xml=true
-->
. This is obtained in the XSL document by
using <xsl:comment> onepage_xml=true </xsl:comment>
If the output XML or HTML is to be processed by
grid rules, then the output must contain the XML comment <!-- enable_grid_rules=true
-->
(and this can be obtained by including <xsl:comment>
enable_grid_rules=true </xsl:comment>
in the
XSL.
Unwired Accelerator automatically transforms HTML with jTidy, then applies the XSL.
Unlike Custom capture, you can only define a single capture possibility.
If a JSP is used to generate the XSL, the following parameters are available to the JSP (as request attributes):
url
html
params – key value pairs extracted from JSP
sessionID – current session ID
conextID
resourceID
bindings
The following Custom XSL sample returns fixed HTML content regardless of the input HTML.
1:<?xml version="1.0"?> 2:<!— 3: This XSL shows an example that outputs fixed HTML content regardless of 4: input HTML 5: It also tells the CCL to enable grid rules 6: --> 7:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 8: <xsl:template match="/"> 9: <xsl:comment> enable_grid_rules=true </xsl:comment> 10: <table class="ONEPAGE_FEGRID_CAPTURE_TABLE"> 11: <tr> 12: <td>col1</td><td>Col2</td> 13: </tr> 14: <tr> 15: <td>A</td><td>B</td> 16: </tr> 17: </table> 18: </xsl:template>19:</xsl:stylesheet>
The following Custom XSL sample returns a grid layout.
1:<?xml version="1.0"?> 2:<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 3: <xsl:template match="/"> 4: <data> 5: <xsl:comment> enable_grid_rules=true </xsl:comment> 6: <xsl:comment> onepage_xml=true </xsl:comment> 7: <Record> 8: <Field>F1</Field> 9: <Field>F2</Field> 10: <Field>F3</Field> 11: <Field>F4</Field> 12: </Record> 13: <Record> 14: <Field>R1</Field> 15: <Field>R2</Field> 16: <Field>R3</Field> 17: <Field>R4</Field> 18: </Record> 19: </data> 20: </xsl:template>21:</xsl:stylesheet>
In both examples, notice the use of <xsl:comment>
tags
to indicate to UA how the output should be treated:
<xsl:comment> enable_grid_rules=true
</xsl:comment>
<xsl:comment> onepage_xml=true </xsl:comment>
Using Custom XSL Web capture
In Mobile Web Studio, open the Application Builder, and click Add. The New Web Element window displays.
In Address, enter the Web address, such as http://localhost:4040/index.jsp
.
Select Custom XSL from the drop-down list. The “XSL file” field displays.
In “XSL file”, enter the XSL file name.
In the Select window, choose the grid, and click Next.
On the Define and Filter windows, make changes, and click Next.
On the Parameters window, you will see the parameters that were used to reach the report you selected. You can click the select box next to them, and customize as needed.
Click Next.
On Window Preview, enter a name for the element. Click Finish to save the element.
In Application Builder, follow the normal Save procedure to name your application, specify List/Detail fields, and mark the application for offline use, and so on.