dpi96151 2016-11-24 13:51
浏览 42

XSL取代P标签

I have a variable in XML which I would like to format. In variable, it's HTML with tags. Our system produces too many p tags, so I would like to remove all <p> and closing </p>. There is text in between p tags, which I want to stay, just remove p and /p tags.

 <xsl:value-of select="php:functionString('str_replace',$remove,'',normalize-space(php:functionString('html_entity_decode',description)))" />

I've tried with this, but this just removes one p and not closing one.

What is the best solution?

Here is the whole template. How i can implement it: thank you for your answer. I completely new to XSL and i didn't managed to get it to work. Here is my the section of the code. I would like to remove p tag from variable description.

<xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" exclude-result-prefixes="php">
<xsl:output method="xml" indent="yes" encoding="UTF-8" omit-xml-declaration="yes"/>

<xsl:template match="/">

<products>
<xsl:for-each select="objects/object">
<xsl:element name="name"><xsl:value-of select="name"/></xsl:element>
<xsl:element name="url"><xsl:value-of select="product_url"/></xsl:element>
<xsl:element name="description"><xsl:value-of select="description"/>           </xsl:element>
</products>
</xsl:template>
</xsl:stylesheet>
  • 写回答

2条回答 默认 最新

  • dqz7636 2016-11-24 16:26
    关注

    Is there a problem with following solution:

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

    So you will match p-tags and will only process their child nodes, like e.g. text and tags.

    评论

报告相同问题?