Reputation: 121
My XML file looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Diese Grammatik wurde abgelehnt - verwenden Sie stattdessen FMPXMLRESULT. -->
<FMPDSORESULT
xmlns="http://www.filemaker.com/fmpdsoresult">
<ERRORCODE>0</ERRORCODE>
<DATABASE>Test.fmp12</DATABASE>
<LAYOUT></LAYOUT>
<ROW MODID="31" RECORDID="1">
<ID_EXPORT>1</ID_EXPORT>
<artikel_nr>14368</artikel_nr>
<sprache>de</sprache>
<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>
</ROW>
</FMPDSORESULT>
Now my problem is, that I only want to change the output from element "spezifikation" because I want to disable the output-escaping like this:
<xsl:value-of select="." disable-output-escaping="yes" />
I found examples like this:
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
But I couldn't figure out how I can make the exception for "spezifikation"?
Upvotes: 0
Views: 1846
Reputation: 70648
First start off with the XSLT identity transform
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
Then, you just need to add another template to match spezifikation
. However, you need to take into account that in your XML you have a default namespace specified
<FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">
If you are using XSLT 1.0, you need to handle this in your template match, by means of a namespace prefix...
<xsl:template match="fm:spezifikation" xmlns:fm="http://www.filemaker.com/fmpdsoresult">
Try this XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="fm:spezifikation" xmlns:fm="http://www.filemaker.com/fmpdsoresult">
<xsl:copy>
<xsl:value-of select="." disable-output-escaping="yes" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
You can simplify things in XSLT 2.0, by using xpath-default-namespace
instead.
Try this XSLT 2.0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xpath-default-namespace="http://www.filemaker.com/fmpdsoresult">
<xsl:output method="xml" indent="yes" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="spezifikation">
<xsl:copy>
<xsl:value-of select="." disable-output-escaping="yes" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Upvotes: 2