我正在尝试使用csharp和xslt更新嵌套记录。我希望能够获得每个TopicAnalysisbyTopicAnalysisID的TopicAnswerID这里是我的xslt代码:
<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>
这是XML数据:
<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>
这是c代码:
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());
}
答案 0 :(得分:0)
有点难以理解您想要做的事情,并且发布的代码存在一些问题。最重要的是处理的性质,这似乎都在一个大根部分。通常,如果您在迭代项目,我们会使用它来梳理它并为我们的元素选择上下文,创建在其他地方查找这些值的变量,等等。但是,我无法理解这些标识符是什么以及应该做什么。例如,你有;
<input type="hidden" id="hiTopicID" name="hiTopicID"
value="{/root/BaseInfo/QueryData/TopicID}" />
但是你的XML输入文件中不存在路径'/ root / BaseInfo / QueryData / TopicID',因此不确定是什么在查找内容。
然而,我怀疑你所追求的是类似的东西;
<!-- 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" />
(将TopicDescription替换为您所追求的任何内容)
我仍然认为现在还不清楚,我怀疑你设置XML数据的上下文的方式和XSLT代码并没有帮助你理解如何最好地解决这个问题。使用...是确保流程更好的最佳方法,并且不会陷入过于复杂的输入XML中。
干杯。 :)