-
Notifications
You must be signed in to change notification settings - Fork 12
/
identify_anonymous_items.xsl
50 lines (43 loc) · 1.99 KB
/
identify_anonymous_items.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2015 – The MITRE Corporation
All rights reserved. See LICENSE.txt for complete terms.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:incident="http://stix.mitre.org/Incident-1"
xmlns:maecBundle="http://maec.mitre.org/XMLSchema/maec-bundle-4"
xmlns:cybox="http://cybox.mitre.org/cybox-2"
exclude-result-prefixes="xs"
version="2.0">
<!--
This xslt stylesheet runs under the mode "identifyAnonymousItems", which
means that any of the specified elements that show up in the source
document without an id or idref, will be assigned an autogenerated id.
-->
<!--
the default behavior for an element is to copy all of its attributes and
its child text and element nodes.
-->
<xsl:template match="@*|node()" mode="identifyAnonymousItems">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<!--
For the specified elements, also copy their attribues and child elements
and text nodes, but if the element does not have an id or idref attribute,
assign an autogenerated id number.
-->
<xsl:template match="*:Observable|*:Indicator|*:TTP|*:Exploit_Target|*:Incident|*:Course_Of_Action|*:Campaign|*:Threat_Actor[not(self::incident:Threat_Actor)]|maecBundle:AV_Classification|*:Associated_Object/cybox:Object|*:Related_Object/cybox:Object|maecBundle:Malware_Instance_Object_Attributes/cybox:Object" mode="identifyAnonymousItems">
<xsl:copy>
<xsl:if test="not(@id) and not(@idref)">
<xsl:variable name="newId" select="generate-id(.)" />
<xsl:attribute name="id" select="concat('AUTO_GENERATED_ID_', $newId)" />
</xsl:if>
<xsl:apply-templates select="@*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>
<xsl:template match="maecBundle:MAEC_Bundle/@id" mode="identifyAnonymousItems">
</xsl:template>
</xsl:stylesheet>