- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要使用单个 XSLT 在 XML 的 CDATA 中转换 XML。
我有一个如下的 XML,CDATA 中有 xml,如下面的 xml 所示。
<message channel-id="e01db0aa-b3db-4b6c-a055-7a0d5c1d1f20" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<send-parameters>
<agent-parameter multi-valued="false">
<name>Networks</name>
<value><![CDATA[<Networks>
<Network>
<GroupCode>EXTPRI</GroupCode>
<NetworkTypeId>LANI</NetworkTypeId>
<OrgNetworkPlatformName>EON-0cbu0cust12301dcd-D-PCL-0002</OrgNetworkPlatformName>
<OrgNetworkPlatformID>urn:vcloud:network:b7ccfd5f-cfd7-48eb-9dd6-1989b08d7b86</OrgNetworkPlatformID>
</Network>
<Network>
<GroupCode>EXTPRI</GroupCode>
<NetworkTypeId>LANI</NetworkTypeId>
<OrgNetworkPlatformName>ABC-0cbu0cust12301dcd-D-PCL-XYZ</OrgNetworkPlatformName>
<OrgNetworkPlatformID>urn:vcloud:network:b7ccfd5f-cfd7-48eb-9dd6-1989b08d7b86</OrgNetworkPlatformID>
</Network>
</Networks>]]></value>
</agent-parameter>
</send-parameters>
</message>
<?xml version="1.0" encoding="UTF-8"?>
<message xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" channel-id="7652d759-4b32-44d4-8a27-9e390f0cae7b">
<send-parameters>
<agent-parameter multi-valued="false">
<name>ExternalPublicOrgNWPlatformID_DDC</name>
<value>EON-0cbu0cust12301dcd-D-PCL-0002</value>
</agent-parameter>
<agent-parameter multi-valued="false">
<name>ExternalPublicOrgNWPlatformID_DS</name>
<value>ABC-0cbu0cust12301dcd-D-PCL-XYZ</value>
</agent-parameter>
</send-parameters>
</message>
最佳答案
此 XSLT 生成所需的输出:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:variable name="cdata"
select="message/send-parameters/agent-parameter/value"/>
<xsl:variable name="parsedXml_">
<xsl:call-template name="parseXml">
<xsl:with-param name="text" select="$cdata"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="parsedXml" select="exsl:node-set($parsedXml_)"/>
<message xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<xsl:attribute name="channel">
<xsl:value-of select="message/@channel-id"/>
</xsl:attribute>
<send-parameters>
<agent-parameter multi-valued="false">
<name>ExternalPublicOrgNWPlatformID_DDC</name>
<value>
<xsl:value-of select="$parsedXml/Networks/Network[1]/OrgNetworkPlatformName"/>
</value>
</agent-parameter>
<agent-parameter multi-valued="false">
<name>ExternalPublicOrgNWPlatformID_DS</name>
<value>
<xsl:value-of select="$parsedXml/Networks/Network[2]/OrgNetworkPlatformName"/>
</value>
</agent-parameter>
</send-parameters>
</message>
</xsl:template>
<xsl:template name="parseXml">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '>')">
<xsl:variable name="topLevelTag">
<xsl:call-template name="getTopLevelTag">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="openingTag">
<xsl:value-of select="$topLevelTag"/>
</xsl:variable>
<xsl:variable name="tagName">
<xsl:call-template name="getTopLevelTagName">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="closingTag">
<xsl:value-of select="concat('</',$tagName,'>')"/>
</xsl:variable>
<xsl:variable name="firstNode">
<xsl:if test="not(contains($topLevelTag,'/>'))">
<xsl:value-of select="substring-before(substring-after($text,$openingTag),$closingTag)"/>
</xsl:if>
</xsl:variable>
<xsl:variable name="afterFirstNode">
<xsl:choose>
<xsl:when test="not(contains($topLevelTag,'/>'))">
<xsl:value-of select="substring-after($text,concat($firstNode,$closingTag))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-after($text,$topLevelTag)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name="{$tagName}">
<xsl:call-template name="createAttributes">
<xsl:with-param name="text" select="$topLevelTag"/>
</xsl:call-template>
<xsl:call-template name="parseXml">
<xsl:with-param name="text" select="$firstNode"/>
</xsl:call-template>
</xsl:element>
<xsl:call-template name="parseXml">
<xsl:with-param name="text" select="$afterFirstNode"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="getTopLevelTagName">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '>')">
<xsl:variable name="tagWithAttributesWithoutEnd">
<xsl:value-of select="substring-before($text, '>')"/>
</xsl:variable>
<xsl:variable name="tagWithAttributesWithoutBegining">
<xsl:value-of select="substring-after($tagWithAttributesWithoutEnd, '<')"/>
</xsl:variable>
<xsl:variable name="tagName">
<xsl:choose>
<xsl:when test="contains($tagWithAttributesWithoutBegining,' ')">
<xsl:value-of
select="substring-before($tagWithAttributesWithoutBegining, ' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$tagWithAttributesWithoutBegining"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$tagName"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="getTopLevelTag">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '>')">
<xsl:variable name="tagWithAttributesWithoutEnd">
<xsl:value-of select="substring-before($text, '>')"/>
</xsl:variable>
<xsl:value-of select="concat($tagWithAttributesWithoutEnd,'>')"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="createAttributes">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '="')">
<xsl:variable name="attributeName">
<xsl:value-of select="substring-before(substring-after($text,' '),'="')"/>
</xsl:variable>
<xsl:message>
<xsl:value-of select="$text"/>
</xsl:message>
<xsl:variable name="attributeValue">
<xsl:value-of select="substring-before(substring-after($text,concat($attributeName,'="')),'"')"/>
</xsl:variable>
<xsl:attribute name="{$attributeName}">
<xsl:value-of select="$attributeValue"/>
</xsl:attribute>
<xsl:call-template name="createAttributes">
<xsl:with-param name="text" select="substring-after($text,concat($attributeName,'="',$attributeValue,'"'))"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
关于xslt - 如何使用xslt解析另一个xml的CDATA中的xml?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14508513/
这个问题在这里已经有了答案: What does in XML mean? (13 个答案) 关闭 8 年前。 我不熟悉 XML 及其相关技术。 这个 CDATA 标签总是在开头,然后是一些东西
我遇到了这种困难的情况,我需要在另一个 CDATA 标签中使用 CDATA 标签。不过,这种情况很容易解释。 我有以下东西: ]]> 出于显示目的,我也需要将我的 Javascript 包装
我是 Blogger 博客用户。我曾经看到一个在 CDATA 标记内定位脚本的模板,如下所示: /**/ 虽然,我之前看到过类似的代码,如下所示: // 唯一不同的是/*
我很确定节可以在 XHTML5 中使用,但是 HTML5 呢? 最佳答案 CDATA structure 根本不是针对 HTML 的,它是针对 XML 的。 人们有时会在 XHTML 里面使用它们 s
我正在尝试删除字符串中的所有 [.*],但不删除 ![CDATA[xxx]]。我期待以下结果 """![CDATA[please remove[macro]]]""" .replaceAll(
不允许在 内堵塞。这是可以理解的。 现在,我必须在 中传输用户输入的数据堵塞。恶意用户可能会输入 或两者兼而有之。 问题是:处理这种情况的首选方法是什么? 剥离 ? 用空格替换它? 用错误消息打
我有一个定义元素“密码”的 XSD。我想允许任何角色存在。目前,我将元素定义为 xs:string用户必须转义字符串(例如 myP&ssword )或将其包含在 CDATA 标记中(例如 )
我在解析 XML 时遇到以下异常 org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM]
我正在尝试使用 powershell 读取 rss 提要,但无法在提要中提取 cdata 部分 这是提要的片段(为了节省空间,剪掉了一些项目): ... text 2011-11-28T
XML文档中的所有文本均会被解析器解析 只有CDATA 区段中的文本会被解析器忽略 PCDATA - 被解析的字符数据 XML解析器通常会解析 XML 文档中所有的文本 当某个XML 元素被解
我需要使用 Javascript 清除该文本 block 的部分内容: Lorem Ipsum is simply dummy text of the printing and typesetting
我看到了 solution让 XmlSerializer 输出 CDATA 部分,但是是否可以根据另一个值有条件地实现这一点? 下面的代码演示了我想要的结果: enum LogItemType {
我正在 Angular 应用程序中进行 soap 调用。 我需要为其中一个调用的有效载荷部分传递 CDDATA angular.forEach(contactsCollection, function
请帮帮我 在终端中: C no longer supported in regex; marked by / 我的文件 perl 中的代码 if ($html =~ //) 解决这个问题的最佳方法是什
我得到一个包含 CDATA 的字符串,我想删除它。 Input : "" Output I want : Hello World 我想获取 之间的所有数据和 并将其添加到
最近,我正在创建一个模块来将谷歌再营销标签添加到网上商店。根据文档,我已经为不同类型的页面(产品、类别、购物车等)准备了 google_tag_params。一切顺利,直到客户使用 Chrome 的
我试图在描述字段中创建 CDATA 部分,但失败了。代码非常简单,但在生成的 XML 中没有出现 CDATA 部分!! Node de = document.createElement("descri
这个问题是由开发人员 Michael Rys 相当激进地拒绝将 CDATA 部分的解析包含到 FOR XML PATH 中引起的,因为 "There is no semantic difference
您好,我这里有一个 CDATA 示例 和 我的 CDATA 正则表达式无法识别这个 "])*"]]>" 这也行不通 "][^\]]*[\]]{2,})*">" 有人可以给我一个 的正则表达式吗?
我经常使用内联 Javascript,通常是在我制作的 WordPress 主题中。我没有听说过在 // 中包装内联 Javascript直到几个月前,几年来我一直在以相当的能力水平做这件事。 我四处
我是一名优秀的程序员,十分优秀!