Skip to content

Commit

Permalink
Merging manually with no-ff Wendell's PR 1976 into develop due to con…
Browse files Browse the repository at this point in the history
…flicts/permissions that prevented the rebase.
  • Loading branch information
iMichaela committed Mar 12, 2024
2 parents c909b22 + 3f19e58 commit 8988c9b
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
78 changes: 78 additions & 0 deletions build/resolve-entities.xspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<x:description xmlns:x="http://www.jenitennison.com/xslt/xspec"
stylesheet="resolve-entities3.xsl"
xmlns="http://csrc.nist.gov/ns/oscal/metaschema/1.0">

<x:scenario label="Everything copies:">
<x:scenario label="A bare metaschema">
<x:context>
<METASCHEMA/>
</x:context>
<x:expect label="copies" select="$x:context"/>
</x:scenario>
<x:scenario label="With random PIs">
<x:context>
<?xml-stylesheet href="some.css"?>
<METASCHEMA>
<title>A test</title>
<?random?>
</METASCHEMA>
</x:context>
<x:expect label="copies" select="$x:context"/>
</x:scenario>
<x:scenario label="A comment" pending="dev"/>
</x:scenario>

<x:scenario label="import/@href is modified:">
<x:scenario label="providing a suffix to the base name">
<x:context>
<METASCHEMA>
<import href="some.other.metaschema.xml"/>
</METASCHEMA>
</x:context>
<x:expect label="copies with @href modified">
<METASCHEMA>
<import href="some.other.metaschema_RESOLVED.xml"/>
</METASCHEMA>
</x:expect>
</x:scenario>
<x:scenario label="even when the suffix is not 'xml'">
<x:context>
<METASCHEMA>
<import href="some.other.metaschema"/>
</METASCHEMA>
</x:context>
<x:expect label="copies with @href modified">
<METASCHEMA>
<import href="some.other_RESOLVED.metaschema"/>
</METASCHEMA>
</x:expect>
</x:scenario>
<x:scenario label="or it is missing entirely">
<x:context>
<METASCHEMA>
<import href="some_metaschema"/>
</METASCHEMA>
</x:context>
<x:expect label="copies with @href modified">
<METASCHEMA>
<import href="some_metaschema_RESOLVED"/>
</METASCHEMA>
</x:expect>
</x:scenario>
<x:scenario label="providing a suffix to the base name">
<x:context>
<x:param name="splice">_NEW</x:param>
<METASCHEMA>
<import href="some.other.metaschema.xml"/>
</METASCHEMA>
</x:context>
<x:expect label="copies with @href modified">
<METASCHEMA>
<import href="some.other.metaschema_NEW.xml"/>
</METASCHEMA>
</x:expect>
</x:scenario>
</x:scenario>

</x:description>
46 changes: 46 additions & 0 deletions build/resolve-entities3.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xpath-default-namespace="http://csrc.nist.gov/ns/oscal/metaschema/1.0"
exclude-result-prefixes="xs math"
version="3.0">

<!--
Purpose: Process XML files through a parsing/serialization that resolves internal parsed entities.
Also renames file references in METASCHEMA/import/@href
using $importHrefSuffix to suffix the base name
so for $importHrefSuffix='NEW'
import href="a_metaschema_module.xml" becomes href="a_metaschema_module_NEW.xml"
Otherwise this is an identity transform, so a diff over source and results should show only stated changes.
Parameter: $importHrefSuffix is 'RESOLVED' by default
XSpec: See the XSpec resolve-entities.xspec for functional testing, including the edge cases.
Compared to old resolve-entities.xsl: This XSLT provides the same outputs
for 'normal' inputs i.e. when import/@href ends in '.xml'.
For extraordinary inputs it does a little differently.
-->

<!-- since whitespace is retained from input, it provides indenting
- if (schema-based) strip-space is operative, switch @indent to 'yes'-->
<xsl:output omit-xml-declaration="no" indent="no" encoding="ASCII"/>

<xsl:param name="importHrefSuffix" select="'RESOLVED'"/>

<!-- copying everything through -->
<xsl:mode on-no-match="shallow-copy"/>

<xsl:template match="import/@href">
<xsl:param name="splice" select="'_' || $importHrefSuffix"/>

<xsl:variable name="basename" select="replace(.,'\.[^.]*$','')"/>
<xsl:attribute name="href" select="$basename || $splice || substring-after(.,$basename)"/>
</xsl:template>

</xsl:stylesheet>

0 comments on commit 8988c9b

Please sign in to comment.