XSL mit copy

okah

Grünschnabel
hallo,

ich bin neu bei der Programmierung von XML oder XSL Dateien, falls ich etwas nicht geneu beschreibe,
hoffe ich das ihr es mir nachsehnt.

ich möchte eine XSL-Transformation nach XML durchführen.

Ich habe folgende XML Datei:

<Report mod="a" content="b">
<Column id="1001" exp="C1">
<Test id="1" use="opt">
this is optional
</Test>
</Column>
</Report>


Das soll das Ziel sein:

<Report mod="a" content="b">
<Column id="1001" exp="C1">
<Test id="1" use="opt">
</Test>
</Column>
</Report>

Also nur den Inhalt von <Test> will ich nicht ausgeben. Alles andere wird kopiert.

Folgendes XSLT wende ich an:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Report">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Column">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Test">
<xsl:copy>
<xsl:apply-templates select="@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

Es funktioniert aber nicht richtig.

Könnt ihr mir helfen?
wäre um jeden tip dankbar!
Vielen Dank
 
Hallo,

du musst nur im Identity-Template den betreffenden Textknoten löschen, der ansonsten auch dann kopiert wird, wenn es im Template nicht expressiv vermerkt ist (Default-Template).
XSL:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

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

    <xsl:template match="Test/text()">
            <xsl:apply-templates select="@*|node()"/>
    </xsl:template>

</xsl:stylesheet>
Schon fertig. ;)
 

Neue Beiträge

Zurück