-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging manually with no-ff Wendell's PR 1976 into develop due to con…
…flicts/permissions that prevented the rebase.
- Loading branch information
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |