Skip to content

Commit

Permalink
switched to having the icon templates use a shared function
Browse files Browse the repository at this point in the history
also now the switch between iconReferenceStyle == "inlineLiteralXml" and iconReferenceStyle == "dataUri" is now working
  * data urs with base64 encoded svg data are now usable
  * inlineLiteralXml is the default

change also allows the stylesheet parameter to be passed in to the main stylesheet (stix-to-html.xsl) and used in the (now imported) icons.xsl

this supports issue #23
  • Loading branch information
mattcoarr committed Mar 5, 2014
1 parent 215e2dc commit 660c454
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 45 deletions.
85 changes: 42 additions & 43 deletions icons.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,78 +25,77 @@
xmlns:ns_sfw="http://ns.adobe.com/SaveForWeb/1.0/"
xmlns:ns_custom="http://ns.adobe.com/GenericCustomNamespace/1.0/"
xmlns:ns_adobe_xpath="http://ns.adobe.com/XPath/1.0/">

<xsl:param name="iconReferenceStyleVariable" select="''" />

<xsl:template name="iconGeneric">
<xsl:param name="class" />
<xsl:param name="baseFilename" />

<xsl:function name="stix:generateIconGeneric">

<xsl:param name="class" as="xs:string" />
<xsl:param name="baseFilename" as="xs:string" />

<div>
<xsl:attribute name="class" select="string-join(('itemCategoryIcon', $class), ' ')" />
<xsl:copy-of select="doc(concat($baseFilename, '.svg'))" />

<!--
iconReferenceStyle:
* inlineLiteralXml
* dataUri
* relativeUri
-->
<xsl:choose>
<xsl:when test="$iconReferenceStyleVariable = 'inlineLiteralXml'">
<xsl:copy-of select="doc(concat($baseFilename, '.svg'))" />
</xsl:when>

<xsl:when test="$iconReferenceStyleVariable = 'dataUri'">
<xsl:variable name="base64Data" select="unparsed-text(concat($baseFilename, '.svg.base64'))" />
<img><xsl:attribute name="src" select="concat('data:image/svg+xml;base64,', $base64Data)" /></img>
</xsl:when>

<xsl:when test="$iconReferenceStyleVariable = 'relativeUri'">
<img><xsl:attribute name="src" select="concat($baseFilename, '.svg')" /></img>
</xsl:when>

<xsl:otherwise>(icon reference style parameter set to invalid option</xsl:otherwise>
</xsl:choose>

</div>
</xsl:template>

</xsl:function>
<xsl:template name="iconCampaigns">
<xsl:call-template name="iconGeneric">
<xsl:with-param name="class" select="'iconCampaigns'" />
<xsl:with-param name="baseFilename" select="'images/campaign'" />
</xsl:call-template>
<xsl:copy-of select="stix:generateIconGeneric('iconCampaigns', 'images/campaign')" />
</xsl:template>

<xsl:template name="iconCOAs">
<xsl:call-template name="iconGeneric">
<xsl:with-param name="class" select="'iconCoa'" />
<xsl:with-param name="baseFilename" select="'images/course_of_action'" />
</xsl:call-template>
<xsl:copy-of select="stix:generateIconGeneric('iconCoa', 'images/course_of_action')" />
</xsl:template>

<xsl:template name="iconDataMarkings">
<xsl:call-template name="iconGeneric">
<xsl:with-param name="class" select="'iconDataMarkings'" />
<xsl:with-param name="baseFilename" select="'images/data_marking'" />
</xsl:call-template>
<xsl:copy-of select="stix:generateIconGeneric('iconDataMarkings', 'images/data_marking')" />
</xsl:template>

<xsl:template name="iconExploitTargets">
<xsl:call-template name="iconGeneric">
<xsl:with-param name="class" select="'iconExploitTargets'" />
<xsl:with-param name="baseFilename" select="'images/explit_target'" />
</xsl:call-template>
<xsl:copy-of select="stix:generateIconGeneric('iconExploitTargets', 'images/exploit_target')" />
</xsl:template>

<xsl:template name="iconIncidents">
<xsl:call-template name="iconGeneric">
<xsl:with-param name="class" select="'iconIncident'" />
<xsl:with-param name="baseFilename" select="'images/incident'" />
</xsl:call-template>
<xsl:copy-of select="stix:generateIconGeneric('iconIncidents', 'images/incident')" />
</xsl:template>

<xsl:template name="iconIndicators">
<xsl:call-template name="iconGeneric">
<xsl:with-param name="class" select="'iconIndicators'" />
<xsl:with-param name="baseFilename" select="'images/indicator'" />
</xsl:call-template>
<xsl:copy-of select="stix:generateIconGeneric('iconIndicators', 'images/indicator')" />
</xsl:template>

<xsl:template name="iconObservables">
<xsl:call-template name="iconGeneric">
<xsl:with-param name="class" select="'iconObservables'" />
<xsl:with-param name="baseFilename" select="'images/observable'" />
</xsl:call-template>
<xsl:copy-of select="stix:generateIconGeneric('iconObservables', 'images/observable')" />
</xsl:template>

<xsl:template name="iconThreatActors">
<xsl:call-template name="iconGeneric">
<xsl:with-param name="class" select="'iconThreatActors'" />
<xsl:with-param name="baseFilename" select="'images/threat_actor'" />
</xsl:call-template>
<xsl:copy-of select="stix:generateIconGeneric('iconThreatActors', 'images/threat_actor')" />
</xsl:template>

<xsl:template name="iconTTPs">
<xsl:call-template name="iconGeneric">
<xsl:with-param name="class" select="'iconTTPs'" />
<xsl:with-param name="baseFilename" select="'images/ttp'" />
</xsl:call-template>
<xsl:copy-of select="stix:generateIconGeneric('iconTTPs', 'images/ttp')" />
</xsl:template>

</xsl:stylesheet>
9 changes: 7 additions & 2 deletions stix_to_html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ [email protected]
xmlns:EmailMessageObj="http://cybox.mitre.org/objects#EmailMessageObject-2"
exclude-result-prefixes="cybox xsi fn EmailMessageObj">

<xsl:import href="icons.xsl"/>

<xsl:output method="html" omit-xml-declaration="yes" indent="yes" media-type="text/html"
version="4.0"/>


<!--
how to set parameters: xslt stylesheet parameters should be passed in via
whatever mechanism the xslt engine has. saxon allows you to set parameters
Expand Down Expand Up @@ -82,17 +85,19 @@ [email protected]
* relativeUri - normal html image style references, e.g. <img src="images/logo.svg" />
-->
<xsl:param name="iconReferenceStyle" select="'inlineLiteralXml'" />

<!--
do you want to display the constraints in cyboxProperties-style displays?
usually the answer is true(), but if you want a more concise display, set to false().
-->
<xsl:param name="displayConstraints" select="true()"/>

<xsl:include href="stix_common.xsl"/>
<xsl:include href="icons.xsl"/>
<xsl:include href="normalize.xsl"/>

<!-- do not modify this, this is used inside icons.xsl to pass in the value of the iconReferenceStyle parameter -->
<xsl:variable name="iconReferenceStyleVariable" select="$iconReferenceStyle" />

<xsl:variable name="isRootStix" select="fn:exists(/stix:STIX_Package)" />
<xsl:variable name="isRootCybox" select="fn:exists(/cybox:Observables)" />

Expand Down

0 comments on commit 660c454

Please sign in to comment.