I am trying to use <xsl:copy-of>
to submit copies of two XML nodes along with a form. The problem is that I'm only getting the node's text content instead of all of the full node content. According to w3schools:
The
<xsl:copy-of>
element creates a copy of the current node. Note: Namespace nodes, child nodes, and attributes of the current node are automatically copied as well!
But, this doesn't seem to be happening for me -- either I don't understand the note, or I'm using the <xsl:copy-of>
element incorrectly. I've included snippets of my xml, xsl, and jQuery below (I apply the xsl to the xml, which creates an html form, which uses jQuery to submit). I've also included the output I'm currently getting along with the desired output. Any suggestions are much appreciated!
The XML looks like this:
<trigger offsetBeg="89" offsetEnd="96">induced</trigger>
<ggps>
<ggp role="Theme" offsetBeg="68" offsetEnd="73" id="10013"
consensusName="HDAC6">HDAC6</ggp>
<ggp role="Cause" offsetBeg="100" offsetEnd="103" id="7001"
consensusName="TSA">TSA</ggp>
</ggps>
The XSL looks like this:
<xsl:variable name="trigger"><xsl:copy-of select="trigger" /></xsl:variable>
<xsl:variable name="ggps"><xsl:copy-of select="ggps" /></xsl:variable>
<form name="label_form" action="">
<input class="trigger" type="hidden" name="trigger" value="{$trigger}" />
<input class="ggps" type="hidden" name="ggps" value="{$ggps}" />
<div><button class="button">Submit</button></div>
</form>
When I add this to the XSL:
<xsl:copy-of select="current()/trigger"></xsl:copy-of>
<xsl:copy-of select="current()/ggps"></xsl:copy-of>
I get this HTML:
<trigger offsetBeg="89" offsetEnd="96">induced</trigger>
<ggps>
<ggp role="Theme" offsetBeg="68" offsetEnd="73" id="10013"
consensusName="HDAC6">HDAC6</ggp>
<ggp role="Cause" offsetBeg="100" offsetEnd="103" id="7001"
consensusName="TSA">TSA</ggp>
</ggps>
I'm using jQuery to do the form submission:
$(".button").click(function() {
var trigger = $(this).parent().siblings("input.trigger").val();
var ggps = $(this).parent().siblings("input.ggps").val();
var dataString = 'trigger=' + trigger + '&ggps=' + ggps;
$.ajax({
type : "POST",
url : "/submit_label",
data : dataString,
success : function(){
console.log("dataString:\n" + dataString);
}
});
return false;
});
What I'm getting out of console.log is this:
dataString:
trigger='induced '&ggps=' HDAC6 TSA '
What I want to get from console.log would be this:
dataString:
trigger='<trigger offsetBeg="89" offsetEnd="96">induced</trigger>'&ggps='<ggps>
<ggp role="Theme" offsetBeg="68" offsetEnd="73"id="10013"consensusName="HDAC6">
HDAC6</ggp><ggp role="Cause" offsetBeg="100" offsetEnd="103" id="7001"
consensusName="TSA">TSA</ggp></ggps>'
I want this, because I want to be able to drop these nodes directly into another XML document that I'll be building.