i want transform xmi files using xslt. works fine, not understand why <body> tag values "version 1.0" , "eauml version:1.0" copied template "packagedelement" (see output).
xmi file:
<?xml version="1.0" encoding="windows-1252"?> <xmi:xmi xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/uml/2.1" xmlns:xmi="http://schema.omg.org/spec/xmi/2.1" xmlns:thecustomprofile="http://www.sparxsystems.com/profiles/thecustomprofile/1.0" xmlns:eauml="http://www.sparxsystems.com/profiles/eauml/1.0"> <uml:model xmi:type="uml:model" name="ea_model" visibility="public"> <packagedelement xmi:type="uml:package" name="test" visibility="public"> ... </packagedelement> </uml:model> <xmi:extension> <profiles> <uml:profile xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/uml/2.1/" xmlns:xmi="http://schema.omg.org/spec/xmi/2.1" xmi:id="thecustomprofile" nsprefix="thecustomprofile" name="thecustomprofile" metamodelreference="mmref01"> <ownedcomment xmi:type="uml:comment" xmi:id="comment01" annotatedelement="thecustomprofile"> <body> version:1.0</body> </ownedcomment> <packagedelement xmi:type="uml:stereotype" xmi:id="enum" name="enum"/> ... </uml:profile> <uml:profile xmi:version="2.1" xmlns:uml="http://schema.omg.org/spec/uml/2.1/" xmlns:xmi="http://schema.omg.org/spec/xmi/2.1" xmi:id="8c9e6706-8" nsprefix="eauml" name="eauml" metamodelreference="mmref01"> <ownedcomment xmi:type="uml:comment" xmi:id="comment01" annotatedelement="8c9e6706-8"> <body>eauml version:1.0</body> </ownedcomment> ... </uml:profile> </profiles> </xmi:extension> </xmi:xmi> xslt file (code inside <xsl:if> irrelevant problem):
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:xmi="http://schema.omg.org/spec/xmi/2.1" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:uml="http://www.omg.org/spec/uml/20131001" xmlns:ecore="http://www.eclipse.org/emf/2002/ecore"> <xsl:strip-space elements="*"/> <xsl:output indent="yes"/> <xsl:template match="/"> <ecore:epackage> <xsl:apply-templates mode="packagedelement" /> </ecore:epackage> </xsl:template> <xsl:template match="packagedelement" mode="packagedelement"> <xsl:if test="(@xmi:type='uml:package')"> </xsl:if> </xsl:template> </xsl:stylesheet> output:
<?xml version="1.0"?> <ecore:epackage xmlns:ecore="http://www.eclipse.org/emf/2002/ecore" xmlns:xmi="http://schema.omg.org/spec/xmi/2.1" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:uml="http://www.omg.org/spec/uml/20131001"> version:1.0 eauml version:1.0 </ecore:epackage>
what see result of built-in template rules being applied nodes aren't matched explicitly 1 of templates.
to solve this, either add template preventing text nodes being copied default:
<xsl:template match="text()" mode="packagedelement"/> or - preferably, imho - apply templates more selectively.
Comments
Post a Comment