public final class XSLT
extends java.lang.Object
<code> Document oDocument = new Document(); String xml = "<books>" + "<book>"+ "<name>abc</name>"+ "<type>computer</type>"+ "</book>"+ "<book>"+ "<name>xyz</name>"+ "<type>science fiction</type>"+ "</book>"+ "</books>" ; String xsl= "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + "<xsl:template match=\"books\">"+ "<books>"+ "<xsl:apply-templates/>"+ "</books>"+ "</xsl:template>"+ "<xsl:template match=\"name\">"+ "<name>"+ "<xsl:apply-templates/>"+ "</name>"+ "</xsl:template>"+ "<xsl:template match=\"book\">"+ "<book>"+ "<xsl:apply-templates/>"+ "</book>"+ "</xsl:template>"+ "<xsl:template match=\"type\">"+ "<genre>"+ "<xsl:apply-templates/>"+ "</genre>"+ "</xsl:template>"+ "</xsl:stylesheet>"; iXml = oDocument.parseString(xml); XSLT oXSL = XSLT.parseFromString(xsl); if(oXSL != null) { int iTransformedXML = oXSL.xslTransform(iXml); System.out.println(Node.writeToString(iTransformedXML, true)); } The code changes the tag name from "type" to "genre" in the given xml and prints the transformed xml. <code>
Modifier and Type | Method and Description |
---|---|
void |
delete()
Deletes the native handle of the
XSLT object |
protected void |
finalize() |
static XSLT |
parseFromFile(java.lang.String stFileName) |
static XSLT |
parseFromString(java.lang.String stXSL) |
java.lang.String |
xslStrTransform(int iNomNode,
XPathMetaInfo oMetaInfo)
Deprecated.
use xslTransformToString()
|
int |
xslTransform(int iNomNode)
It is used for xml to xml conversion.
|
int |
xslTransform(int iNomNode,
XPathMetaInfo oMetaInfo)
Deprecated.
use xslTransform(int iNomNode)
<code> Document oDocument = new Document(); int iXml = oDocument.parseString(xmlStr); //xmlStr has the xml content in String format. XSLT oXSL = XSLT.parseFromString(xslStr); //xslStr has the xsl content in String format. if(oXSL != null) { int iTransformedXML = oXSL.xslTransform(iXml,null); System.out.println(Node.writeToString(iTransformedXML, true)); } </code> |
void |
xslTransformToFile(java.lang.String stFileName,
int iNomNode)
It is used for generic transformation.
|
void |
xslTransformToFile(java.lang.String stFileName,
int iNomNode,
XPathMetaInfo oMetaInfo)
Deprecated.
use xslTransformToFile(String stFileName, int iNomNode).
Example: <code> Document oDocument = new Document(); int iXml = oDocument.parseString(xmlStr); //xmlStr has the xml content in String format. XSLT oXSL = XSLT.parseFromString(xslStr); //xslStr has the xsl content in String format. if(oXSL != null) { oXSL.xslTransformToFile("./name.xml",iXml,null); //The transformed result will be in "name.xml". } </code> |
java.lang.String |
xslTransformToString(int iNomNode)
It is used for generic transformation.
|
java.lang.String |
xslTransformToString(int iNomNode,
XPathMetaInfo oMetaInfo)
Deprecated.
use xslTransformToString(int iNomNode).
Example: <code> Document oDocument = new Document(); int iXml = oDocument.parseString(xmlStr); //xmlStr has the xml content in String format. XSLT oXSL = XSLT.parseFromString(xslStr);//xslStr has the xsl content in String format. if(oXSL != null) { String str = oXSL.xslTransformToString(iXml,null); } </code> |
public static XSLT parseFromFile(java.lang.String stFileName)
stFileName
- The xsl filenameXslException
if the parser could
not parse the file <code> XSLT oXSL = XSLT.parseFromFile(fileName); </code>
public static XSLT parseFromString(java.lang.String stXSL)
stXSL
- The string containing xslXslException
if the parser could
not parse the string <code> XSLT oXSL = XSLT.parseFromString(xsl); <br/> </code>
public void delete()
XSLT
object
<code> XSLT oXSL = XSLT.parseFromString(xsl); oXSL.delete(); </code>
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public int xslTransform(int iNomNode)
iNomNode
- The NOM node corresponds to the xml to be transformed.<code> Document oDocument = new Document(); int iXml = oDocument.parseString(xmlStr); //xmlStr has the xml content in String format. XSLT oXSL = XSLT.parseFromString(xslStr); //xslStr has the xsl content in String format. if(oXSL != null) { int iTransformedXML = oXSL.xslTransform(iXml); System.out.println(Node.writeToString(iTransformedXML, true)); } </code>
public int xslTransform(int iNomNode, XPathMetaInfo oMetaInfo)
<code> Document oDocument = new Document(); int iXml = oDocument.parseString(xmlStr); //xmlStr has the xml content in String format. XSLT oXSL = XSLT.parseFromString(xslStr); //xslStr has the xsl content in String format. if(oXSL != null) { int iTransformedXML = oXSL.xslTransform(iXml,null); System.out.println(Node.writeToString(iTransformedXML, true)); } </code>
iNomNode
- The NOM node corresponds to the xml to be transformed.oMetaInfo
- The MetaInfoObjectpublic java.lang.String xslStrTransform(int iNomNode, XPathMetaInfo oMetaInfo)
iNomNode
- The NOM nodeoMetaInfo
- The MetaInfoObjectpublic java.lang.String xslTransformToString(int iNomNode)
iNomNode
- The NOM node corresponds to the xml to be transformed.<code> Document oDocument = new Document(); int iXml = oDocument.parseString(xmlStr); //xmlStr has the xml content in String format. XSLT oXSL = XSLT.parseFromString(xslStr);//xslStr has the xsl content in String format. if(oXSL != null) { String str = oXSL.xslTransformToString(iXml); } </code>
public java.lang.String xslTransformToString(int iNomNode, XPathMetaInfo oMetaInfo)
<code> Document oDocument = new Document(); int iXml = oDocument.parseString(xmlStr); //xmlStr has the xml content in String format. XSLT oXSL = XSLT.parseFromString(xslStr);//xslStr has the xsl content in String format. if(oXSL != null) { String str = oXSL.xslTransformToString(iXml,null); } </code>
iNomNode
- The NOM node corresponds to the xml to be transformed.oMetaInfo
- The MetaInfoObjectpublic void xslTransformToFile(java.lang.String stFileName, int iNomNode)
stFileName
- The output file nameiNomNode
- The NOM node corresponds to the xml to be transformed. <code> Document oDocument = new Document(); int iXml = oDocument.parseString(xmlStr); //xmlStr has the xml content in String format. XSLT oXSL = XSLT.parseFromString(xslStr); //xslStr has the xsl content in String format. if(oXSL != null) { oXSL.xslTransformToFile("./name.xml",iXml); //The transformed result will be in "name.xml". } </code>
public void xslTransformToFile(java.lang.String stFileName, int iNomNode, XPathMetaInfo oMetaInfo)
<code> Document oDocument = new Document(); int iXml = oDocument.parseString(xmlStr); //xmlStr has the xml content in String format. XSLT oXSL = XSLT.parseFromString(xslStr); //xslStr has the xsl content in String format. if(oXSL != null) { oXSL.xslTransformToFile("./name.xml",iXml,null); //The transformed result will be in "name.xml". } </code>
stFileName
- The output file nameiNomNode
- The NOM node corresponds to the xml to be transformed.oMetaInfo
- The MetaInfoObject