Subject: [xsl] Delete element except one child From: Hind Al-Hakami <h_alhakami@xxxxxxxxx> Date: Fri, 12 May 2006 00:11:22 -0700 (PDT) |
Hi All, How can I do the following: If "UML:Package" has "xmi.idref" attribute then delete its grand-Pa element bolck. Otherwise delete "UML:Package" element except the children of its child element "UML:Namespase.ownedElement" Source: ... <UML:Package xmi.id = '.:00000000000007CC' name = 'java' isSpecification = 'false' isRoot = 'false' isLeaf = 'false' isAbstract = 'false'> <UML:Namespace.ownedElement> <UML:Package xmi.id = '.:00000000000007CB' name = 'lang' isSpecification = 'false' isRoot = 'false' isLeaf = 'false' isAbstract = 'false'> <UML:Namespace.ownedElement> <UML:Class xmi.id = '.:000000000000085D' name = 'String' visibility = 'public' isSpecification = 'false' isRoot = 'false' isLeaf = 'false' isAbstract = 'false' isActive = 'false'> <UML:ModelElement.taggedValue> <UML:TaggedValue xmi.id = '.:000000000000085E' isSpecification = 'false'> <UML:TaggedValue.dataValue>yes</UML:TaggedValue.dataValue> <UML:TaggedValue.type> <UML:TagDefinition xmi.idref = '.:000000000000085F'/> </UML:TaggedValue.type> </UML:TaggedValue> </UML:ModelElement.taggedValue> </UML:Class> </UML:Namespace.ownedElement> </UML:Package> Target: <UML:Class xmi.id = '.:000000000000085D' name = 'String' visibility = 'public' isSpecification = 'false' isRoot = 'false' isLeaf = 'false' isAbstract = 'false' isActive = 'false'> <UML:ModelElement.taggedValue> <UML:TaggedValue xmi.id = '.:000000000000085E' isSpecification = 'false'> <UML:TaggedValue.dataValue>yes</UML:TaggedValue.dataValue> <UML:TaggedValue.type> <UML:TagDefinition xmi.idref = '.:000000000000085F'/> </UML:TaggedValue.type> </UML:TaggedValue> </UML:ModelElement.taggedValue> </UML:Class> XSLT Code: <xsl:template match="*[name(descendant::*[2]) = 'UML:Package']"> <xsl:choose> <xsl:when test="string-length(descendant::UML:Package/@xmi.idref) > 0"/> </xsl:choose> </xsl:template> <xsl:template match="UML:Package"> <xsl:copy> <xsl:copy-of select="UML:Namespace.ownedElement/@*"/> </xsl:copy> </xsl:template> Full XSLT Code: <?xml version='1.0' ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:UML="org.omg.xmi.namespace.UML" xmlns:a="http://graphml.graphdrawing.org/xmlns/graphml"> <xsl:output method="xml"/> <xsl:template match="/"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <xsl:template match="UML:Namespace.ownedElement[local-name(parent::*[1]) = 'Model']"> <xsl:element name="UML:Namespace.ownedElement"> <xsl:call-template name="graphml"/> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> <!--<xsl:copy-of select="descendant::UML:Namespace.ownedElement/*"/> <xsl:call-template name="package"/> --> </xsl:element> </xsl:template> <xsl:template name="graphml"> <xsl:for-each select="//a:graphml/.//a:cluster"> <xsl:choose> <xsl:when test="count(child::*) > 1"> <xsl:variable name="cOne" select="child::*[1]/@name"/> <xsl:variable name="cTwo" select="child::*[2]/@name"/> <xsl:if test="not((count(child::*) = '2') and ((contains($cOne, '.java') and contains($cOne, $cTwo)) or (contains($cTwo, '.java') and contains($cTwo, $cOne))))"> <xsl:element name="UML:Component"> <xsl:attribute name="xmi.id"> <xsl:text>.:000</xsl:text> <xsl:value-of select="@id"/> </xsl:attribute> <xsl:attribute name="isSpecification">false</xsl:attribute> <xsl:attribute name="isRoot">false</xsl:attribute> <xsl:attribute name="isLeaf">false</xsl:attribute> <xsl:attribute name="isAbstract">false</xsl:attribute> <xsl:copy-of select="@name"/> <xsl:element name="UML:ModelElement.clientDependency"> <xsl:for-each select="a:node"> <xsl:element name="UML:Dependency"> <xsl:attribute name="xmi.idref"> <xsl:value-of select="@xmi.id"/> </xsl:attribute> <xsl:apply-templates/> </xsl:element> </xsl:for-each> </xsl:element> </xsl:element> </xsl:if> </xsl:when> </xsl:choose> </xsl:for-each> </xsl:template> <xsl:template match="*[name(descendant::*[2]) = 'UML:Package']"> <xsl:choose> <xsl:when test="string-length(descendant::UML:Package/@xmi.idref) > 0"/> </xsl:choose> </xsl:template> <xsl:template match="UML:Package"> <xsl:copy> <xsl:copy-of select="UML:Namespace.ownedElement/@*"/> </xsl:copy> </xsl:template> <xsl:template match="a:graphml"/> </xsl:stylesheet> Thanks in Advance, Hind __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] select text of current elemen, Karen McAdams | Thread | Re: [xsl] Delete element except one, G. Ken Holman |
[xsl] select text of current elemen, Karen McAdams | Date | Re: [xsl] Delete element except one, G. Ken Holman |
Month |