html tags is getting ignored in xsl

Here should go questions about transforming XML with XSLT and FOP.
mebimathew
Posts: 7
Joined: Mon Nov 05, 2007 1:00 pm
Location: India

html tags is getting ignored in xsl

Post by mebimathew »

hi all...
i have a problem .
Let me first give my complete files

This is my xml

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>
This is my xsl

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>
this is my java code

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 "";
}
}
Now i will explain my problem.xsl is calling two methods in java one is substituteSingleQuote and the other one is encryptString.
The output which i am getting in the encryptString method is GmailGmail1.The output which i should get is <a href="http://www.gmail.com">Gmail</a>
<a href="http://www.gmail.com">Gmail1</a>
I dont know why this is happening.This is a serious problem in my project.Can anyone help regarding this issue...
Help will be appreciated
Hi all
mebimathew
Posts: 7
Joined: Mon Nov 05, 2007 1:00 pm
Location: India

Post by mebimathew »

Hi all
One thing i forgot to say is in xsl i am talking about <!-- Feedback Related parameters --> part
I gave the complete code so that everyone can understand what i am trying to say
Hi all
mebimathew
Posts: 7
Joined: Mon Nov 05, 2007 1:00 pm
Location: India

Post by mebimathew »

Hi
can Anyone reply to the above topic..it is very important
Thanks
Post Reply