Xml 使用xslt删除嵌入的html标记

Xml 使用xslt删除嵌入的html标记,xml,xslt,xslt-1.0,xslt-2.0,Xml,Xslt,Xslt 1.0,Xslt 2.0,我的输入xml在Emp_Name和Country元素中嵌入了html标记,我只需要去掉html标记即可获得下面所需的输出 请您协助如何在XSLT中实现这一点 输入XML: <root> <Record> <Emp_ID>288237</Emp_ID> <Emp_Name> <br>John</br></Emp_Name> <Country><p>US</p>&l

我的输入xml在Emp_Name和Country元素中嵌入了html标记,我只需要去掉html标记即可获得下面所需的输出

请您协助如何在XSLT中实现这一点

输入XML:

 <root>
 <Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name> <br>John</br></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>

288237

约翰
美国

遗嘱 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>

288237
约翰
美国
遗嘱
5/12/2014
9年
abc
JAVA

如果您事先知道使用了哪些HTML标记,您可以执行以下操作:

XSLT1.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"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="br|p">
    <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
<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:value-of select="."/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>


编辑: 有没有可能像我一样为这两个字段显式地编写xslt 接收该元素的任何html标记(而不仅仅是

那么:

XSLT1.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"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="br|p">
    <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
<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:value-of select="."/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

如果您事先知道使用了哪些HTML标记,您可以执行以下操作:

XSLT1.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"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="br|p">
    <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
<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:value-of select="."/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>


编辑: 有没有可能像我一样为这两个字段显式地编写xslt 接收该元素的任何html标记(而不仅仅是

那么:

XSLT1.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"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="br|p">
    <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
<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:value-of select="."/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

如果您事先知道使用了哪些HTML标记,您可以执行以下操作:

XSLT1.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"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="br|p">
    <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
<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:value-of select="."/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>


编辑: 有没有可能像我一样为这两个字段显式地编写xslt 接收该元素的任何html标记(而不仅仅是

那么:

XSLT1.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"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="br|p">
    <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
<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:value-of select="."/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

如果您事先知道使用了哪些HTML标记,您可以执行以下操作:

XSLT1.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"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="br|p">
    <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
<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:value-of select="."/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>


编辑: 有没有可能像我一样为这两个字段显式地编写xslt 接收该元素的任何html标记(而不仅仅是

那么:

XSLT1.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"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="br|p">
    <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>
<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:value-of select="."/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>



感谢您提供的解决方案。但是,有没有可能显式地为这两个元素编写xslt,因为我可能会收到该元素的任何html标记(不仅仅是
和)。@michael.hor257k:工作正常。但是,当我尝试在我们的工具中调用这个xslt时,输入XML标记被感知为,并且可以编写xslt来基于和剥离html标记吗?我已修改了问题中的输入XML。@Vivek修改上述答案无法回答您的新问题。它需要一种完全不同的方法。请开始一个新问题。@michael.hor257k谢谢您的回复。我在下面的帖子里开始了一个新问题。谢谢你的解决方案。但是,有没有可能显式地为这两个元素编写xslt,因为我可能会收到该元素的任何html标记(不仅仅是
和)。@michael.hor257k:工作正常。但是,当我尝试在我们的工具中调用这个xslt时,输入XML标记被感知为,并且可以编写xslt来基于和剥离html标记吗?我已修改了问题中的输入XML。@Vivek修改上述答案无法回答您的新问题。它需要一种完全不同的方法。请开始一个新问题。@michael.hor257k谢谢您的回复。我在下面的帖子里开始了一个新问题。谢谢你的解决方案。但是,有没有可能显式地为这两个元素编写xslt,因为我可能会收到该元素的任何html标记(不仅仅是
和)。@michael.hor257k:工作正常。但是,当我尝试在我们的工具中调用这个xslt时,输入XML标记被感知为,并且可以编写xslt来基于和剥离html标记吗?我已修改了问题中的输入XML。@Vivek修改上述答案无法回答您的新问题。它需要一种完全不同的方法。请开始一个新问题。@michael.hor257k谢谢您的回复。我在下面的帖子里开始了一个新问题。谢谢你的解决方案。但是,有没有可能显式地为这两个元素编写xslt,因为我可能会收到该元素的任何html标记(不仅仅是
和)。@michael.hor257k:工作正常。但是,当我尝试在我们的工具中调用这个xslt时,输入XML标记被感知为,并且可以编写xslt来基于和剥离html标记吗?我已修改了问题中的输入XML。@Vivek修改上述答案无法回答您的新问题。它需要一种完全不同的方法。请开始一个新问题。@michael.hor257k谢谢您的回复。我在下面的帖子里开始了一个新问题。我把你的问题退回到原来的形式,因为新的问题是根本不同的。请发布一个新问题。我已经将您的问题回滚到原来的形式,因为新问题根本不同。请发布一个新问题。我已经将您的问题回滚到原来的形式,因为新问题根本不同。请发布一个新问题。我已经将您的问题回滚到原来的形式,因为新问题根本不同。请发一个新问题。