Page 1 of 1
html tags is getting ignored
Posted: Mon Nov 05, 2007 1:08 pm
by mebimathew
Hi all
i have a problem is that when i pass some variables like html tags from xsl to java method the html tag is being ignored.
for example
<i>hi</i> the output is coming as hi.but the hi is not in italics.
the code of my xml is
Code: Select all
<material> <matextension><a href="http://www.orkut.com">Orkut</a>
<a href="http://www.gmail.com">Gmail</a></matextension> </material>
the code for my xsl is
Code: Select all
<xsl:variable name="fbText">
<xsl:choose>
<xsl:when test="material/matextension">
<xsl:for-each select="material/matextension">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select = "normalize-space(material/mattext)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="encryptedfbText" select="util:getModifiedString($fbText)"/>
<script language="javascript">
alert('encryptedfbText is <xsl:value-of select="$encryptedfbText"/>')
</script>
<xsl:template match="h1|h2|h3|h4|h5|h6|b|big|i|small|s|strike|sub|sup|tt|u|font|br|pre|center|hr|blockquote|q|address|ins|del|div|p|abbr|acronym|cite|code|dfn|em|strong|samp|var|span|area|map|ol|ul|dir|li|dl|dt|dd|table|tr|td|th|thead|tfoot|tbody|caption|applet|param|script|form|input|textarea|select|option">
<xsl:copy-of select="."/>
</xsl:template>
the code for my java is
Code: Select all
public static String getModifiedString(Node node) {
String temp = nodeToString( node);
return temp;
}
static final TransformerFactory fac = TransformerFactory.newInstance();
public static String nodeToString(Node node) {
try {
DOMSource source = new DOMSource(node);
Transformer transformer = fac.newTransformer();
transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
transformer.transform(source, result);
return writer.toString();
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
can anyone help regarding this issue
Posted: Mon Nov 05, 2007 5:12 pm
by jkmyoung
The problem is probably in the XSLT.
You're probably using <xsl:value-of select="...."/> somewhere, which copies the text only. You'd have to use apply-templates where it is instead, so that the <i> template gets used instead.
If you post the source xml that contains that italics, it'd be easier to see.
Posted: Mon Nov 05, 2007 6:25 pm
by sorin_ristache
Hello,
You did not give an example of the output that you want for the example XML input file. If you just want to surround the content of material/matextension with the <i> and </i> tags or you want to keep that content as is I think you do not need a Java extension because these operations can be done easily in XSLT. Is it really necessary to apply an XSLT transformation on a DOM node in a Java extension? I think you should do such operations which can be done in XSLT without a Java extension.
Regards,
Sorin
Posted: Wed Nov 07, 2007 3:23 pm
by mebimathew
Hi Sorin
Thanks for the reply..
The output which i want is <i>hi</i>.i dont want the output as hi.
Why i am using java is because i need to encrypt the output.
The problem now is in the java code.in the java, the method getModifiedString is returning the <i>hi</i>.50% of the output got correct.
But have another problem is that if i put <b>hello</b><h1>how are you</h1>.The output which i am getting is <b>hello</b> I am not getting the <h1>how are you</h1>.the actually output which i want is <b>hello</b><h1>how are you</h1>
Another example is that if i put <b>hello</b>hi.the output which i am getting is <b>hello</b>.
I think now you understand the problem
Once again thanks
Regards Mese
Posted: Wed Nov 07, 2007 3:42 pm
by sorin_ristache
Can you post a small and complete input XML file, the complete XSLT stylesheet and the output that you want to generate from the input XML file? From your code fragments it is not clear what transformation should be applied to the input.
Regards,
Sorin
Posted: Tue Nov 20, 2007 11:20 am
by mebimathew
Hi Sorin
Sorry i was busy with some other things.I am sending the complete xml file and xsl file.
My xml is
Code: Select all
<questestinterop>
<section ident="ROOT" title="Multiple Choice Quiz">
<qticomment> MC </qticomment>
<sectionobjectives view="Candidate" >
<material> <mattext></mattext> </material>
</sectionobjectives>
<item ident="1" title="Question 1">
<presentation label="LID">
<response_lid ident="LID1">
<material> <matextension><a href="http://www.gmail.com">GMAIL</a>
Hello how is the work gng on</matextension> </material>
<render_choice shuffle="No">
<response_label ident="LID1_1">
<material> <matextension><a href="http://www.gmail.com">Gmail</a>
hellow how is the work gng on</matextension> </material>
</response_label>
<response_label ident="LID1_2">
<material> <mattext>Not required</mattext> </material>
</response_label>
<response_label ident="LID1_3">
<material> <mattext>Not required</mattext> </material>
</response_label>
<response_label ident="LID1_4">
<material> <mattext>Not required</mattext> </material>
</response_label>
</render_choice>
</response_lid>
</presentation>
<resprocessing>
<outcomes><decvar/></outcomes>
<respcondition>
<conditionvar>
<varequal respident="LID1" >LID1_1</varequal>
</conditionvar>
<displayfeedback feedbacktype="Response" linkrefid="LID1_FBK1" />
</respcondition>
<respcondition>
<conditionvar>
<varequal respident="LID1" >LID1_2</varequal>
</conditionvar>
<displayfeedback feedbacktype="Response" linkrefid="LID1_FBK2" />
</respcondition>
<respcondition>
<conditionvar>
<varequal respident="LID1" >LID1_3</varequal>
</conditionvar>
<displayfeedback feedbacktype="Response" linkrefid="LID1_FBK3" />
</respcondition>
<respcondition>
<conditionvar>
<varequal respident="LID1" >LID1_4</varequal>
</conditionvar>
<displayfeedback feedbacktype="Response" linkrefid="LID1_FBK4" />
</respcondition>
</resprocessing>
<itemfeedback title="Correct Answer" ident="LID1_FBK1">
<material> <matextension><a href="http://www.gmail.com">Gmail</a>
<a href="http://www.gmail.com">Gmail1</a></matextension> </material>
</itemfeedback>
<itemfeedback title="Answer 2 Selected" ident="LID1_FBK2">
<material> <mattext>Not required</mattext> </material>
</itemfeedback>
<itemfeedback title="Answer 3 Selected" ident="LID1_FBK3">
<material> <mattext>Not required</mattext> </material>
</itemfeedback>
<itemfeedback title="Answer 4 Selected" ident="LID1_FBK4">
<material> <mattext>Not required</mattext> </material>
</itemfeedback>
</item>
</section>
</questestinterop>
My xsl is
Code: Select all
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:util="olc.shared.util.Utils"
xmlns:java="java"
exclude-result-prefixes="util java" >
<xsl:output method="html" indent="no"/>
<xsl:template match="section" mode = "createQuizParameters">
<!-- Question Related parameters -->
<script language="javascript">
<xsl:for-each select="./item">
<xsl:variable name="questionId">
<xsl:value-of select = "presentation/response_lid/@ident"/>
</xsl:variable>
<xsl:variable name="questionTitle">
<xsl:value-of select = "@title"/>
</xsl:variable>
<xsl:variable name="questionText">
<xsl:choose>
<xsl:when test="presentation/response_lid/material/matextension">
<xsl:for-each select="presentation/response_lid/material/matextension">
<xsl:value-of select = "normalize-space(.)"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select = "normalize-space(presentation/response_lid/material/mattext)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="question">
question<xsl:value-of select = "$questionId"/>
</xsl:variable>
<xsl:variable name="answer">
answerObjectArray<xsl:value-of select = "$questionId"/>
</xsl:variable>
var <xsl:value-of select="$answer"/> = new Array();
var <xsl:value-of select="$question"/> = new makeQuestionObject('<xsl:value-of select = "$questionId"/>','<xsl:value-of select = "$questionTitle"/>', '<xsl:value-of select = "util:substituteSingleQuote(string($questionText))"/>');
<!-- Answer Related parameters -->
<xsl:for-each select="./presentation/response_lid/render_choice/response_label">
<xsl:variable name="answerText">
<xsl:choose>
<xsl:when test="material/matextension">
<xsl:for-each select="material/matextension">
<xsl:value-of select = "normalize-space(.)"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select = "normalize-space(material/mattext)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$answer"/>[<xsl:value-of select="position()"/>] = new makeAnswerObject('<xsl:value-of select = "@ident"/>','<xsl:value-of select = "util:substituteSingleQuote(string($answerText))"/>');
</xsl:for-each>
<!-- Answer-Feedback mapping -->
<xsl:for-each select="./resprocessing/respcondition">
<xsl:value-of select="$answer"/>[<xsl:value-of select="position()"/>].feedbackId = '<xsl:value-of select = "displayfeedback/@linkrefid"/>';
</xsl:for-each>
<!-- Feedback Related parameters -->
<xsl:for-each select="./itemfeedback">
<xsl:if test="@title != 'Hint'">
<xsl:variable name="fbTitle">
<xsl:value-of select = "@title"/>
</xsl:variable>
<xsl:variable name="fbText">
<xsl:choose>
<xsl:when test="material/matextension">
<xsl:for-each select="material/matextension">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select = "normalize-space(material/mattext)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="encryptedfbTitle" select="util:encryptString(string(./@title))"/>
<xsl:variable name="fbTextModified" select="util:substituteSingleQuote(string($fbText))"/>
<xsl:variable name="encryptedfbText" select="util:encryptString(string($fbTextModified))"/>
<xsl:value-of select="$answer"/>[<xsl:value-of select="position()"/>].feedBackTitle = '<xsl:value-of select = "$encryptedfbTitle"/>';
<xsl:value-of select="$answer"/>[<xsl:value-of select="position()"/>].feedBackText = '<xsl:value-of select = "$encryptedfbText"/>';
</xsl:if>
</xsl:for-each>
<xsl:value-of select="$question"/>.answerObjectsArray=<xsl:value-of select="$answer"/>;
questionObjectArray[<xsl:value-of select="@ident"/>]=<xsl:value-of select="$question"/>;
</xsl:for-each>
</script>
</xsl:template>
<xsl:template match="section" mode = "createEssayQuizParameters">
<!-- Question Related parameters -->
<script language="javascript">
<xsl:for-each select="./item">
<xsl:variable name="questionId">
<xsl:value-of select = "presentation/response_str/@ident"/>
</xsl:variable>
<xsl:variable name="questionTitle">
<xsl:value-of select = "@title"/>
</xsl:variable>
<xsl:variable name="questionText">
<xsl:choose>
<xsl:when test="presentation/response_str/render_fib/material/matextension">
<xsl:for-each select="presentation/response_str/render_fib/material/matextension">
<xsl:value-of select="normalize-space(.)"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(presentation/response_str/render_fib/material/mattext)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="question">
question<xsl:value-of select = "$questionId"/>
</xsl:variable>
<xsl:variable name="answer">
answerObjectArray<xsl:value-of select = "$questionId"/>
</xsl:variable>
var pos = <xsl:value-of select="@ident"/>;
var <xsl:value-of select="$answer"/> = new Array();
var <xsl:value-of select="$question"/> = new makeQuestionObject('<xsl:value-of select = "$questionId"/>','<xsl:value-of select = "$questionTitle"/>', '<xsl:value-of select = "util:substituteSingleQuote(string($questionText))"/>');
<!-- Answer Related parameters -->
<xsl:for-each select="./presentation/response_str/render_fib/response_label">
<xsl:variable name="answerText">
<xsl:choose>
<xsl:when test="material/matextension">
<xsl:for-each select="material/matextension">
<xsl:value-of select = "normalize-space(.)"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select = "normalize-space(material/mattext)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$answer"/>[<xsl:value-of select="position()"/>] = new makeAnswerObject('<xsl:value-of select = "@ident"/>','<xsl:value-of select = "util:substituteSingleQuote(string($answerText))"/>');
</xsl:for-each>
<!-- Answer-Feedback mapping -->
<xsl:for-each select="./resprocessing/respcondition">
<xsl:value-of select="$answer"/>[<xsl:value-of select="position()"/>].feedbackId = '<xsl:value-of select = "displayfeedback/@linkrefid"/>';
</xsl:for-each>
<!-- Feedback Related parameters -->
<xsl:for-each select="./itemfeedback">
<xsl:if test="@title != 'Hint'">
<xsl:variable name="fbText">
<xsl:choose>
<xsl:when test="material/matextension">
<xsl:for-each select="material/matextension">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select = "normalize-space(material/mattext)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="encryptedfbTitle" select="util:encryptString(string(./@title))"/>
<xsl:variable name="fbTextModified" select="util:substituteSingleQuote(string($fbText))"/>
<xsl:variable name="encryptedfbText" select="util:encryptString(string($fbTextModified))"/>
<xsl:value-of select="$answer"/>[<xsl:value-of select="position()"/>].feedBackTitle = '<xsl:value-of select = "$encryptedfbTitle"/>';
<xsl:value-of select="$answer"/>[<xsl:value-of select="position()"/>].feedBackText = '<xsl:value-of select = "$encryptedfbText"/>';
</xsl:if>
</xsl:for-each>
<xsl:value-of select="$question"/>.answerObjectsArray=<xsl:value-of select="$answer"/>;
questionObjectArray[<xsl:value-of select="@ident"/>]=<xsl:value-of select="$question"/>;
</xsl:for-each>
</script>
</xsl:template>
<xsl:template match="h1|h2|h3|h4|h5|h6|b|big|i|small|s|strike|sub|sup|tt|u|font|br|pre|center|hr|blockquote|q|address|ins|del|div|p|abbr|acronym|cite|code|dfn|em|strong|samp|var|span|area|map|ol|ul|dir|li|dl|dt|dd|table|tr|td|th|thead|tfoot|tbody|caption|applet|param|script|form|input|textarea|select|option">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="H1|H2|H3|H4|H5|H6|B|BIG|I|SMALL|S|STRIKE|SUB|SUP|TT|U|FONT|BR|PRE|CENTER|HR|BLOCKQUOTE|Q|ADDRESS|INS|DEL|DIV|P|ABBR|ACRONYM|CITE|CODE|DFN|EM|STRONG|SAMP|VAR|SPAN|AREA|MAP|OL|UL|DIR|LI|DL|DT|DD|TABLE|TR|TD|TH|THEAD|TFOOT|TBODY|CAPTION|APPLET|PARAM|SCRIPT|FORM|INPUT|TEXTAREA|SELECT|OPTION">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
My java code is
Code: Select all
public static String substituteSingleQuote(String original) {
if (original == null) return "";
String singleQuote = "'";
String singleQuoteEntity = "'";
if (original.indexOf(singleQuote) < 0)
return original;
StringBuffer orig = new StringBuffer("");
int position = original.indexOf(singleQuote);
while (position >= 0) {
int ampEntityPos = original.indexOf(singleQuoteEntity);
orig.append(original.substring(0, position));
orig.append(singleQuoteEntity);
if (ampEntityPos == position)
original = original.substring(position + singleQuoteEntity.length());
else
original = original.substring(position + singleQuote.length());
position = original.indexOf(singleQuote);
}
orig.append(original);
return orig.toString();
}
public static String encryptString(String text){
System.out.println(text);
StringBuffer buff = new StringBuffer();
int key = 150;
if((!text.equals(""))&&(!text.equals(null))){
int length = text.length();
for ( int i=0; i<length ; i++ ){
buff.append((char)( text.charAt(i) ^ key ));
}
buff.append(key);
return buff.toString();
}else{
return "";
}
}
The XSL is calling substituteSingleQuote and encryptString methods.The output which i should get in the encryptString method is <a href="http://www.gmail.com">Gmail</a>
<a href="http://www.gmail.com">Gmail1</a>