如何用XSL仅修改XML中spezifikation元素并禁用输出转义?
How to Disable Output Escaping for the
<spezifikation> Element in XSLT Great question! Since you already have the identity template (which copies all content by default), you just need to add a specific template with higher priority to handle the <spezifikation> element differently. The key here is also accounting for the XML namespace in your input—otherwise the template won't match the element correctly.
Here's the complete XSLT solution:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fmp="http://www.filemaker.com/fmpdsoresult"> <!-- Your existing identity template - handles all elements not matched by other templates --> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <!-- Specialized template for the spezifikation element (with namespace) --> <xsl:template match="fmp:spezifikation"> <xsl:copy> <xsl:copy-of select="@*"/> <!-- Disable output escaping to render the embedded XML as actual nodes --> <xsl:value-of select="." disable-output-escaping="yes"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
Let's break this down:
- Namespace Declaration: We added
xmlns:fmp="http://www.filemaker.com/fmpdsoresult"to map the input's namespace to a prefix (fmp). This is critical because all elements in your XML are part of this namespace, so the template needs to reference it to match<spezifikation>. - Specialized Template: The
match="fmp:spezifikation"template takes precedence over the generic identity template. It copies the<spezifikation>element itself and any attributes it might have, then uses<xsl:value-of select="." disable-output-escaping="yes"/>to output the embedded XML content without escaping—so your<row>and other tags become actual XML elements in the output. - Identity Template: All other elements (like
<ERRORCODE>,<ROW>, etc.) will still be processed by your original identity template, so their content remains unchanged.
Example Output for <spezifikation>:
Instead of seeing escaped text like:
<spezifikation><row><titel>HDMI Port Auflösung</titel>...</row></spezifikation>
You'll get the unescaped XML structure:
<spezifikation> <row> <titel>HDMI Port Auflösung</titel> <attribbut>3840x2160 (UHD) @ 24/25/30 Hz</attribbut> <attribbut>2560x1440 (QHD) @ 30/60 Hz</attribbut> </row> <row> <titel>Material</titel> <attribbut>Holz</attribbut> <attribbut>Stein</attribbut> <attribbut>Aluminium</attribbut> </row> </spezifikation>
内容的提问来源于stack exchange,提问作者dida110
相关产品推荐
相关产品推荐

