here is my _ignoreText.xsl file
<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" indent="no" />
<xsl:template match="*|@*|text()|comment()|processing-instruction()" >
<xsl:if test="normalize-space(.) != '' or ./@* != ''">
<xsl:copy>
<xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()"/>
</xsl:copy>
</xsl:if>
<xsl:variable name="type">
<xsl:choose>
<xsl:when test=". castable as xs:integer">
<xsl:text>Integer</xsl:text>
</xsl:when>
<xsl:when test=". castable as xs:boolean">
<xsl:text>Boolean</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>String</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
</xsl:template>
</xsl:stylesheet>
below is a java code in which i am using above _ignoreText.xsl file to transform xml
import org.custommonkey.xmlunit.Transform;
import java.io.File;
public class TransformDemo1 {
public static void main(String args[]) throws Exception {
String xsltfilename="D:\\Demo\\src\\test\\java\\StringXml\\_ignoreText.xsl";
File xsltfile=new File(xsltfilename);
String strSource = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\" xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\">\n" +
" <SOAP-ENV:Body>\n" +
" <return>\n" +
" <ICD10Flag>hello</ICD10Flag>\n" +
" <status>success</status>\n" +
" </return>\n" +
" </SOAP-ENV:Body>\n" +
"</SOAP-ENV:Envelope>\n";
Transform docSource = new Transform(strSource, xsltfile);
}
}
following is the Error i am getting.
ERROR: 'Syntax error in '. castable as xs:integer'.'
FATAL ERROR: 'file:/D:/Demo/src/test/java/StringXml/_ignoreText.xsl: line 18: Required attribute 'test' is missing.'
Exception in thread "main" org.custommonkey.xmlunit.exceptions.ConfigurationException: file:/D:/RijvanPactPOC/2/DemoProjectPactConsumer/src/test/java/StringXml/_ignoreText.xsl: line 18: Required attribute 'test' is missing.
at org.custommonkey.xmlunit.Transform.getTransformer(Transform.java:201)
at org.custommonkey.xmlunit.Transform.<init>(Transform.java:161)
at org.custommonkey.xmlunit.Transform.<init>(Transform.java:92)
at StringXml.TransformDemo1.main(TransformDemo1.java:31)
Caused by: javax.xml.transform.TransformerConfigurationException: file:/D:/Demo/src/test/java/StringXml/_ignoreText.xsl: line 18: Required attribute 'test' is missing.
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1061)
at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:817)
at org.custommonkey.xmlunit.Transform.getTransformer(Transform.java:196)
... 3 more
Process finished with exit code 1
please suggest any solution or any other Library using that i can Transform the XML based the data type of the value the xml tag is containing
Ex. 1
<status>success</status>
should be transformed to
<status>String</status>
Ex. 2
<status>123</status>
should be transformed to
<status>Integer</status>