2016-05-10 4 views
0

ich eine Quelle xml haben, sieht das wie folgt:XSLT, wie erkennt man ein anderes Muster während der Transformation?

<root> 
    <CompoundPredicate booleanOperator="surrogate"> 
    <CompoundPredicate booleanOperator="and"> 
     <True /> 
     <SimplePredicate field="MODELYEAR" operator="lessOrEqual" value="1999" /> 
    </CompoundPredicate> 
    <False /> 
    </CompoundPredicate> 

    <CompoundPredicate booleanOperator="surrogate"> 
    <CompoundPredicate booleanOperator="and"> 
     <True /> 
     <SimplePredicate field="MODELYEAR" operator="lessOrEqual" value="1999" /> 
    </CompoundPredicate> 
    <SimplePredicate field="AGE" operator="lessOrEqual" value="40" /> 
    <False /> 
    </CompoundPredicate> 
</root> 

Ich möchte eine Transformation in einer solchen Art und Weise durchzuführen, dass 1). Wenn nur das Element "False" nach dem inneren Element "CompoundPredicate" vorhanden ist, löschen Sie das äußere Element "CompoundPredicate" und das Element, das nach dem inneren Element "CompoundPredicate" angezeigt wird. Zum Beispiel

<CompoundPredicate booleanOperator="surrogate"> 
    <CompoundPredicate booleanOperator="and"> 
    <True /> 
    <SimplePredicate field="MODELYEAR" operator="lessOrEqual" value="1999" /> 
    </CompoundPredicate> 
    <False /> 
</CompoundPredicate> 

wird

<CompoundPredicate booleanOperator="and"> 
    <True /> 
    <SimplePredicate field="MODELYEAR" operator="lessOrEqual" value="1999" /> 
    </CompoundPredicate> 

2), wenn es andere Elemente nach dem inneren Element 'CompoundPredicate' eine andere Bedeutung als 'False', dann löschen Sie nur 'False' Element, das nach der inneren erscheint 'CompoundPredicate' Element. Zum Beispiel

<CompoundPredicate booleanOperator="surrogate"> 
    <CompoundPredicate booleanOperator="and"> 
     <True /> 
     <SimplePredicate field="MODELYEAR" operator="lessOrEqual" value="1999" /> 
    </CompoundPredicate> 
    <SimplePredicate field="AGE" operator="lessOrEqual" value="40" /> 
    <False /> 
    </CompoundPredicate> 

<CompoundPredicate booleanOperator="surrogate"> 
    <CompoundPredicate booleanOperator="and"> 
     <True /> 
     <SimplePredicate field="MODELYEAR" operator="lessOrEqual" value="1999" /> 
    </CompoundPredicate> 
    <SimplePredicate field="AGE" operator="lessOrEqual" value="40" /> 
    </CompoundPredicate> 

für dieses Problem wird, weiß nicht, ich auch, wie ich anfangen. Ich würde deine Hilfe sehr schätzen. Danke vielmals.

+0

Wird es immer genau eine innere 'CompoundPredicate' sein? –

Antwort

1

Sehen Sie, ob dies Ihnen in die richtige Richtung zeigt. Es ist auf einer Neuformulierung Ihrer Regeln basiert, die nicht korrekt sind oder nicht:

XSLT 1,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> 

<!-- for outer 'CompoundPredicate' that contains only inner 'CompoundPredicate' and/or 'False' --> 
<xsl:template match="root/CompoundPredicate[not(*[not(self::CompoundPredicate or self::False)])]"> 
    <xsl:apply-templates select="CompoundPredicate"/> 
</xsl:template> 

<!-- remove 'False' elements, children of outer 'CompoundPredicate' --> 
<xsl:template match="root/CompoundPredicate/False"/> 

</xsl:stylesheet> 
+0

wow, vielen Dank. Du bist der beste! – Fischlein

Verwandte Themen