亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在循環中將 CDATA 添加到節點值

在循環中將 CDATA 添加到節點值

C#
米琪卡哇伊 2022-06-12 15:16:07
我正在嘗試將 <![CDATA[...]] 添加到循環內生成的值節點。我正在使用 XSLT 和 C#.net。我已經嘗試了幾件事,包括 將 CDATA 添加到 xml 文件 ,但到目前為止似乎沒有任何工作。我什至嘗試按字面意思添加它,但正如預期的那樣,它沒有成功。任何人都可以在這方面幫助我。這是我的節點的生成方式<xsl:for-each select="$OLifE/">                    <DataPoint>                      <Name>Carrier.Requirements<xsl:if test="$NumberOfPayments > 1"><xsl:value-of select="position()"/></xsl:if></Name>                      <Value>Here is the response text</Value></DataPoint>我的預期輸出是<DataPoint>    <Name>Carrier.Requirements1</Name>    <Value><![CDATA[Here is the response text]]</Value></DataPoint><DataPoint>    <Name>Carrier.Requirements2</Name>    <Value><![CDATA[Here is the response text]]</Value></DataPoint><DataPoint>    <Name>Carrier.Requirements3</Name>    <Value><![CDATA[Here is the response text]]</Value></DataPoint>如果需要任何進一步的信息,請告訴我。
查看完整描述

1 回答

?
溫溫醬

TA貢獻1752條經驗 獲得超4個贊

這是一個簡化的示例:


XML


<input>

    <item/>

    <item/>

    <item/>

</input>

XSLT 1.0


<xsl:stylesheet version="1.0" 

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" cdata-section-elements="Value"/>

<xsl:strip-space elements="*"/>


<xsl:template match="/input">

    <output>

        <xsl:for-each select="item">

            <DataPoint>

                <Name>

                    <xsl:value-of select="concat('Carrier.Requirements', position())"/>

                </Name>

                <Value>Here is the response text</Value>

            </DataPoint>

        </xsl:for-each>

    </output>

</xsl:template>


</xsl:stylesheet>

結果


<?xml version="1.0" encoding="utf-16"?>

<output>

  <DataPoint>

    <Name>Carrier.Requirements1</Name>

    <Value><![CDATA[Here is the response text]]></Value>

  </DataPoint>

  <DataPoint>

    <Name>Carrier.Requirements2</Name>

    <Value><![CDATA[Here is the response text]]></Value>

  </DataPoint>

  <DataPoint>

    <Name>Carrier.Requirements3</Name>

    <Value><![CDATA[Here is the response text]]></Value>

  </DataPoint>

</output>

演示:https ://xsltfiddle.liberty-development.net/94hvTAn


查看完整回答
反對 回復 2022-06-12
  • 1 回答
  • 0 關注
  • 176 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號