如何使用 xsl 变量获取需要更新的记录的子 ID?

发布于 2024-10-27 08:00:38 字数 8789 浏览 1 评论 0原文

我正在尝试使用 csharp 和 xslt 更新嵌套记录。我希望能够通过 TopicAnalysisID 获取每个 TopicAnalysis 的 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&#39;t have a radio, TV, computer or
            any friends, you cannot avoid the exaggerated hype about &quot;social
            media&quot; 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());
        }

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());
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤芳又自赏 2024-11-03 08:00:38

很难遵循你想要做的事情,并且发布的代码存在一些问题。最重要的是加工的本质,这一切似乎都在一个大的根部分中。通常,如果您要迭代项目,我们通常会对其进行梳理并选择元素的上下文,创建在其他地方查找这些值的变量,等等。但是,我无法理解这些标识符是什么以及应该做什么。例如,你有;

<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 的最佳方法。

干杯。 :)

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. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文