How do I use an xsl variable to get the child id of a record i need to update?
I am trying to update a nested record using csharp and xslt. I want to be able to get at the TopicAnswerID for each TopicAnalysisbyTopicAnalysisID Here is my xslt code:
<xsl:when test="/root/BaseInfo/QueryData/m = 'EditAnalysis'">
<form action="topics.aspx?m=SaveExistingAnalysis" name="UpdateAnalysis"
enctype="multipart/form-data" method="post">
<input type="hidden" id="hiTopicID" name="hiTopicID"
value="{/root/BaseInfo/QueryData/TopicID}" />
<input type="hidden" id="hiTopicAnalysisID" name="hiTopicAnalysisID"
value="{/root/TopicAnalysisbyTopicAnalysisID/TopicAnalysisID}" />
<xsl:value-of select="/root/TopicAnalysisbyTopicAnalysisID/TopicName" />
</strong>
<xsl:value-of select="/root/TopicAnalysisbyTopicAnalysisID/TopicDescription" />
<xsl:value-of
select="/root/TopicAnalysisbyTopicAnalysisID/TopicAnalysisTextPending" />
<xsl:for-each select="/root/TopicAnalysisbyTopicAnalysisID">
<xsl:开发者_如何学运维variable name="TOPIC_ANSWER_ID" select="TopicAnswerID" />
<xsl:value-of select="TopicQuestionText" />
<input type="hidden" id="hiTopicAnswerID" name="hiTopicAnswerID"
value="{TopicAnswerID}" />
<xsl:value-of select="AnswerTextPending" />
</xsl:for-each>
</form>
</xsl:when>
Here is the XML data:
<root>
<BaseInfo>
<QueryData>
<m>EditAnalysis</m>
<aid>124</aid>
<t>none</t>
</QueryData>
</BaseInfo>
<PageName>Topics</PageName>
<TopicAnalysisbyTopicAnalysisID>
<TopicID>6</TopicID>
<TopicName>Privacy</TopicName>
<TopicDescription>Testing this out...</TopicDescription>
<topicanalysistextpendingcount>27</topicanalysistextpendingcount>
<answertextpendingcount>36</answertextpendingcount>
<TopicAnalysisID>124</TopicAnalysisID>
<TopicAnalysisText />
<TopicAnalysisTextPending>asdasdasdasdasdasdasdasdasd</TopicAnalysisTextPending>
<AdminUserID>4</AdminUserID>
<TopicQuestionID>4</TopicQuestionID>
<TopicQuestionText>How can you best compete with your competitors?</TopicQuestionText>
<TopicAnswerID>71</TopicAnswerID>
<AnswerTextPending>asdasdasdasdasdasdasdasdasdasdasdasd</AnswerTextPending>
<AnswerText />
</TopicAnalysisbyTopicAnalysisID>
<TopicAnalysisbyTopicAnalysisID>
<TopicID>6</TopicID>
<TopicName>Privacy</TopicName>
<TopicDescription>Testing this out...</TopicDescription>
<topicanalysistextpendingcount>27</topicanalysistextpendingcount>
<answertextpendingcount>42</answertextpendingcount>
<TopicAnalysisID>124</TopicAnalysisID>
<TopicAnalysisText />
<TopicAnalysisTextPending>asdasdasdasdasdasdasdasdasd</TopicAnalysisTextPending>
<AdminUserID>4</AdminUserID>
<TopicQuestionID>3</TopicQuestionID>
<TopicQuestionText>How do you forsee this topic impacting your
financial institution in the next year?</TopicQuestionText>
<TopicAnswerID>72</TopicAnswerID>
<AnswerTextPending>asdasdasdasdasdasdasdasdasdasdasdasdasdasd</AnswerTextPending>
<AnswerText />
</TopicAnalysisbyTopicAnalysisID>
<Topics>
<TopicID>1</TopicID>
<IsHotTopic>true</IsHotTopic>
<IsActive>true</IsActive>
<TopicName>Remote Deposit</TopicName>
<TopicDescription>A wave of banks has adopted RDC, and others consider
it every day. Has it been profitably for your bank? What best
practices have you learned? Which vendors are the best? Is Consumer
RDC on your agenda? Share your RDC content, articles, and more.</TopicDescription>
</Topics>
<Topics>
<TopicID>6</TopicID>
<IsHotTopic>false</IsHotTopic>
<IsActive>false</IsActive>
<TopicName>Privacy</TopicName>
<TopicDescription>Testing this out...</TopicDescription>
</Topics>
<Topics>
<TopicID>5</TopicID>
<IsHotTopic>false</IsHotTopic>
<IsActive>false</IsActive>
<TopicName>BSA/AML</TopicName>
<TopicDescription>Testing this out...</TopicDescription>
</Topics>
<Topics>
<TopicID>3</TopicID>
<IsHotTopic>false</IsHotTopic>
<IsActive>false</IsActive>
<TopicName>Reg E ODP</TopicName>
<TopicDescription>The forced opt-out and opt-back-in for ODP is around
the corner. Many banks will lose significant revenue, even if they
implement a plan. What are your peers doing to soften the blow? What
vendors have emerged to help solve this problem? How much revenue can
you expect to save? Share your Reg E experiences, and learn what your
peers are doing.</TopicDescription>
</Topics>
<Topics>
<TopicID>2</TopicID>
<IsHotTopic>false</IsHotTopic>
<IsActive>false</IsActive>
<TopicName>Social Media</TopicName>
<TopicDescription>Unless you don't have a radio, TV, computer or
any friends, you cannot avoid the exaggerated hype about "social
media" and community banks. Should a bank embrace it or block
it? Is it all sizzle and no steak? What resources are required to
make it work? What are the risks? What are the gains? Share your
perspective and learn from what your peers and consultants think.</TopicDescription>
</Topics>
</root>
Here is the c sharp codes:
else if (Request.Form["SaveExistingAnalysis"] != null)
{
cbancWS.TopicAnalysis tan = new cbancWS.TopicAnalysis();
int topicID = Convert.ToInt32(Request.Form["TopicID"]);
if (tan.TopicAnswers == null)
{
tan.TopicAnswers = new string[15];
}
for (int i = 0; i < Request.Form.Count; i++)
{
string x = Request.Form.Keys[i].ToString();
if (!string.IsNullOrEmpty(x))
{
if (x.Contains("txtA"))
{
tan.TopicAnalysisText = Request.Form[x];
tan.TopicAnalysisTextPending = Request.Form[x];
tan.StatusID = 1;
tan.TopicID = topicID;
tan.AdminUserID = Convert.ToInt32(Request.Form["AdminUserID"]);
tan.TopicAnalysisID = Convert.ToInt32(Request.Form["hiTopicAnalysisID"]);
}
else if (x.Contains("txtQ"))
{
tan.TopicAnalysisText = Request.Form[x];
tan.DateAdded = DateTime.Now;
tan.StatusID = 1;
tan.TopicID = topicID;
TopicAnswer ta = new TopicAnswer();
int qID = GetQuestionNumber(x);
//{TopicAnswerID}
//int aID =
ta.TopicAnswerID = Convert.ToInt32(Request.Form["hiTopicAnswerID"]);
ta.AdminUserID = Convert.ToInt32(Request.Form["AdminUserID"]);
ta.AnswerText = string.Empty;
ta.AnswerTextPending = Request.Form[x];
ta.DateAdded = DateTime.Now;
ta.TopicQuestionID = qID;
ta.TopicAnalysisID = 0;
string swta = cbanc.core.Utility.SerializeObject<TopicAnswer>(ta);
tan.TopicAnswers[i] = swta;
}
}
}
//thisSessionC.BO.AddAnalysis(tan);
XmlData.Append(thisSessionC.BO.GetTopicAnalysis((int)Session["AdminUserID"]).GetXml());
}
Bit hard to follow what you want to do, and there's several problems with the code posted. The foremost is the nature of processing, which all seems to be in one big root section. Often if you are iterating over items, we use to comb through it and select the context for our elements, create variables that look up those values elsewhere, and so on. However, I'm having trouble understanding what these identifiers are and are supposed to do. For example, you have ;
<input type="hidden" id="hiTopicID" name="hiTopicID"
value="{/root/BaseInfo/QueryData/TopicID}" />
But the path '/root/BaseInfo/QueryData/TopicID' doesn't exists in your XML input file, so not sure what's looking up what.
However, what I suspect you're after is something like ;
<!-- First, just a simple variable as a shortcut for a long path -->
<xsl:variable name="lut" select="/root/BaseInfo/QueryData/TopicID" />
<!-- Then, use it for finding a section with a sub-element of that value -->
<xsl:value-of select="/root/TopicAnalysisbyTopicAnalysisID[TopicID=$lut]/TopicDescription" />
(replace TopicDescription with whatever you're after)
I still think it's unclear, and I suspect the way you've set up the context of XML data and XSLT code doesn't aid you in understanding how best to go about this. Using ... is the best way to make sure the flow works better and you don't get bogged down in overly complex input XML.
Cheers. :)
精彩评论