Modifying Element Text
To modify the text in the title element, first retrieve the title node:
<xsl:variable name="titleNodeList"
select="element:getElementsByTagName(
$articleElement, 'title')"/>
<xsl:variable name="titleNode"
select="nodelist:item($titleNodeList, 0)"/>
<xsl:variable name="titleTextNode"
select="node:getFirstChild($titleNode)"/>
Then you can modify the title node's value directly:
<xsl:value-of select="node:setNodeValue(
$titleTextNode, 'Oracle Certified Master')"/>
Modifying the author node follows the same steps.
Although XSLT is typically used for transforming an XML input into another format, sometimes that's not exactly what you need. In this article, you saw how to add power to XSLT by loading an XML file and altering its contents using Java class methods from within the stylesheet itself, using the XSLT extension functions to call the Java class methods from XSLT.
Too see the sample XSLT in action, copy the sample XSLT file parser.xslt shown in Listing 1 to a directory and run it with the command-line utility oraxsl. The syntax of the oraxsl command is:
>oraxsl source stylesheet
To convert the example XML document run the following oraxsl command that specifies parser.xslt as a source and as the stylesheet:
> oraxsl parser.xslt parser.xslt
Extend XSLT Functions
Normally, the first parameter to oraxsl specifies the file the stylesheet named in the second parameter will process; however, because this sample stylesheet doesn't use a source XML document, the first parameter is irrelevant. Still, it's required, and it has to be a valid file, so I simply used the stylesheet file again. In this case, the transformation will work identically regardless of which file you use for the first parameter.
To wrap up, you can use XSLT extension functions to extend the library of functions that XSLT provides. You can store the return values of XSLT extension functions in XSLT variables to use them in your stylesheets. Althoughfor demonstration purposesthis sample doesn't reflect the rule, you should normally use XSLT extension functions only if the XSLT doesn't provide the required functionality.