在XML中剥离Html标记(&;书信电报;及;燃气轮机;使用XSLT
我的输入xml在Emp_Name和Country元素中嵌入了HTML标记。我们的工具正在读取那些HTML标记,如在XML中剥离Html标记(&;书信电报;及;燃气轮机;使用XSLT,xml,xslt,Xml,Xslt,我的输入xml在Emp_Name和Country元素中嵌入了HTML标记。我们的工具正在读取那些HTML标记,如和。我的XML在这两个字段上可以有任何HTML标记 我的要求是剥离这些HTML标记以获得下面所需的输出。 请您协助如何在XSLT中实现这一点 输入XML: <root> <Record> <Emp_ID>288237</Emp_ID> <Emp_Name> <p>John</p&
和
。我的XML在这两个字段上可以有任何HTML标记
我的要求是剥离这些HTML标记以获得下面所需的输出。
请您协助如何在XSLT中实现这一点
输入XML:
<root>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name> <p>John</p></Emp_Name>
<Country><p>US</p></Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>abc</Project>
<Skill>java</Skill>
</Record>
</root>
288237
p约翰/p
pUS/p
遗嘱
5/12/2014
9年
abc
JAVA
期望输出:
<root>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name>John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>abc</Project>
<Skill>java</Skill>
</Record>
</root>
288237
约翰
美国
遗嘱
5/12/2014
9年
abc
JAVA
基本上有两种方法:
禁用输出转义=“yes”
输出转义标记,将转义标记转换为实际标记;序列化输出,并按照本问题上一次迭代中所述处理结果:要“序列化输出”,需要将结果保存到一个新文件,并使用新文件作为输入启动另一个XSLT转换,除非处理器支持另一种序列化形式<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"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Emp_Name|Country">
<xsl:copy>
<xsl:call-template name="remove-markup">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="remove-markup">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string, '<')">
<xsl:value-of select="substring-before($string, '<')" />
<!-- recursive call -->
<xsl:call-template name="remove-markup">
<xsl:with-param name="string" select="substring-after($string, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
应用于您的输入,结果是:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name> John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>abc</Project>
<Skill>java</Skill>
</Record>
</root>
288237
约翰
美国
遗嘱
5/12/2014
9年
abc
JAVA
基本上有两种方法:
禁用输出转义=“yes”
输出转义标记,将转义标记转换为实际标记;序列化输出,并按照本问题上一次迭代中所述处理结果:要“序列化输出”,需要将结果保存到一个新文件,并使用新文件作为输入启动另一个XSLT转换,除非处理器支持另一种序列化形式<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"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Emp_Name|Country">
<xsl:copy>
<xsl:call-template name="remove-markup">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="remove-markup">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string, '<')">
<xsl:value-of select="substring-before($string, '<')" />
<!-- recursive call -->
<xsl:call-template name="remove-markup">
<xsl:with-param name="string" select="substring-after($string, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
应用于您的输入,结果是:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name> John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>abc</Project>
<Skill>java</Skill>
</Record>
</root>
288237
约翰
美国
遗嘱
5/12/2014
9年
abc
JAVA
基本上有两种方法:
禁用输出转义=“yes”
输出转义标记,将转义标记转换为实际标记;序列化输出,并按照本问题上一次迭代中所述处理结果:要“序列化输出”,需要将结果保存到一个新文件,并使用新文件作为输入启动另一个XSLT转换,除非处理器支持另一种序列化形式<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"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Emp_Name|Country">
<xsl:copy>
<xsl:call-template name="remove-markup">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="remove-markup">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string, '<')">
<xsl:value-of select="substring-before($string, '<')" />
<!-- recursive call -->
<xsl:call-template name="remove-markup">
<xsl:with-param name="string" select="substring-after($string, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
应用于您的输入,结果是:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name> John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>abc</Project>
<Skill>java</Skill>
</Record>
</root>
288237
约翰
美国
遗嘱
5/12/2014
9年
abc
JAVA
基本上有两种方法:
禁用输出转义=“yes”
输出转义标记,将转义标记转换为实际标记;序列化输出,并按照本问题上一次迭代中所述处理结果:要“序列化输出”,需要将结果保存到一个新文件,并使用新文件作为输入启动另一个XSLT转换,除非处理器支持另一种序列化形式<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"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Emp_Name|Country">
<xsl:copy>
<xsl:call-template name="remove-markup">
<xsl:with-param name="string" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="remove-markup">
<xsl:param name="string"/>
<xsl:choose>
<xsl:when test="contains($string, '<')">
<xsl:value-of select="substring-before($string, '<')" />
<!-- recursive call -->
<xsl:call-template name="remove-markup">
<xsl:with-param name="string" select="substring-after($string, '>')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
应用于您的输入,结果是:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name> John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>abc</Project>
<Skill>java</Skill>
</Record>
</root>
288237
约翰
美国
遗嘱
5/12/2014
9年
abc
JAVA
@NazafAnwar请不要进行无意义的编辑-尝试真正改进您编辑的帖子。我会在那里。我会记住的。谢谢。:)@马蒂亚斯姆ller@Vivek,您使用哪个XSLT处理器?转义的HTML是XHTML吗?@MartinHonnen我不知道XSLT处理器。我们在datastage中称之为XSLT,它是ETL工具之一。@NazafAnwar请不要进行无意义的编辑-尝试真正改进您编辑的帖子。我会在那里。我会记住的。谢谢。:)@马蒂亚斯姆ller@Vivek,您使用哪个XSLT处理器?转义的HTML是XHTML吗?@MartinHonnen我不知道XSLT处理器。我们在datastage中称之为XSLT,它是ETL工具之一。@NazafAnwar请不要进行无意义的编辑-tr