Skip to content

Commit

Permalink
Merge pull request #197 from metanorma/update
Browse files Browse the repository at this point in the history
SOURCE parsing added, #181
  • Loading branch information
Intelligent2013 authored May 14, 2024
2 parents 773dd43 + 0803612 commit 677ea9e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 39 deletions.
56 changes: 28 additions & 28 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ You will need the `maven` build tool and `make`.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar <XML-FileName>
java -Xss5m -jar target/stepmod2mn-1.59.jar <XML-FileName>
----

e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar data/resource_docs/draughting_elements/resource.xml
java -Xss5m -jar target/stepmod2mn-1.59.jar data/resource_docs/draughting_elements/resource.xml
----

NOTE: resulted AsciiDoc found in data/resource_docs/draughting_elements/document.adoc
Expand All @@ -34,28 +34,28 @@ NOTE: resulted AsciiDoc found in data/resource_docs/draughting_elements/document

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar <XML-FileName> [--output <AsciiDoc-FileName>]
java -Xss5m -jar target/stepmod2mn-1.59.jar <XML-FileName> [--output <AsciiDoc-FileName>]
----

e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar data/resource_docs/draughting_elements/resource.xml --output result_dir/draughting_elements/document.adoc
java -Xss5m -jar target/stepmod2mn-1.59.jar data/resource_docs/draughting_elements/resource.xml --output result_dir/draughting_elements/document.adoc
----

=== Convert all resource.xml and module.xml in the specified folder and sub-folders into the Metanorma AsciiDoc format:

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar <Input-folder>
java -Xss5m -jar target/stepmod2mn-1.59.jar <Input-folder>
----

e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar data/
java -Xss5m -jar target/stepmod2mn-1.59.jar data/
----

NOTE: the result AsciiDocs will be saved in the folder with the source resource.xml and module.xml files.
Expand All @@ -65,57 +65,57 @@ NOTE: the result AsciiDocs will be saved in the folder with the source resource.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar <Input-folder> [--output <Output-folder>]
java -Xss5m -jar target/stepmod2mn-1.59.jar <Input-folder> [--output <Output-folder>]
----

e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar data/ --output documents/
java -Xss5m -jar target/stepmod2mn-1.59.jar data/ --output documents/
----


=== Convert all resource.xml and module.xml in the specified folder and sub-folders into the Metanorma AsciiDoc format, except specified documents:

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar <Input-folder> [--exclude <documents or part numbers list>]
java -Xss5m -jar target/stepmod2mn-1.59.jar <Input-folder> [--exclude <documents or part numbers list>]
----

e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar data/ --exclude "machining_features 104"
java -Xss5m -jar target/stepmod2mn-1.59.jar data/ --exclude "machining_features 104"
----

=== Convert only specified documents resource.xml and module.xml in the specified folder and sub-folders into the Metanorma AsciiDoc format:

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar <Input-folder> [--include-only <documents list>]
java -Xss5m -jar target/stepmod2mn-1.59.jar <Input-folder> [--include-only <documents list>]
----

e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar data/ --include-only "fundamentals_of_product_description_and_support kinematics"
java -Xss5m -jar target/stepmod2mn-1.59.jar data/ --include-only "fundamentals_of_product_description_and_support kinematics"
----

=== Generate Metanorma collection files (metanorma.yml and collection.yml) for the documents specified in the publication index xml file in the tags 'resource_docs' and 'modules':

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar <Publication-Index-XML-FileName>
java -Xss5m -jar target/stepmod2mn-1.59.jar <Publication-Index-XML-FileName>
----

e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar publication/part1000/CR_PMI_5/publication_index.xml
java -Xss5m -jar target/stepmod2mn-1.59.jar publication/part1000/CR_PMI_5/publication_index.xml
----

NOTE: the Metanorma collection files .yml will be saved in the 3 level up folder (usually, source repository's root folder).
Expand All @@ -125,14 +125,14 @@ and save them into the output folder:

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar <Publication-Index-XML-FileName> [--output <Output-folder>]
java -Xss5m -jar target/stepmod2mn-1.59.jar <Publication-Index-XML-FileName> [--output <Output-folder>]
----

e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar iso-10303-srl/iso-10303-stepmod-wg12/publication/part1000/CR_PMI_5/publication_index.xml --output iso-10303-srl/
java -Xss5m -jar target/stepmod2mn-1.59.jar iso-10303-srl/iso-10303-stepmod-wg12/publication/part1000/CR_PMI_5/publication_index.xml --output iso-10303-srl/
----

NOTE: the output folder should contains the folder with the generated .adoc (usually, 'documents'). You can specify this folder obviously by the parameter '--input-documents':
Expand All @@ -141,7 +141,7 @@ e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar iso-10303-srl/iso-10303-stepmod-wg12/publication/part1000/CR_PMI_5/publication_index.xml --output iso-10303-srl/CR_PMI_5 --input-documents iso-10303-srl/documents
java -Xss5m -jar target/stepmod2mn-1.59.jar iso-10303-srl/iso-10303-stepmod-wg12/publication/part1000/CR_PMI_5/publication_index.xml --output iso-10303-srl/CR_PMI_5 --input-documents iso-10303-srl/documents
----

NOTE: the Metanorma collection files (.yml) will be saved in the folder 'iso-10303-srl/CR_PMI_5' and the references point to the documents in the folder iso-10303-srl/documents.
Expand All @@ -151,14 +151,14 @@ NOTE: the Metanorma collection files (.yml) will be saved in the folder 'iso-103

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar <Publication-Index-XML-FileName> [--type <resource_docs or modules>]
java -Xss5m -jar target/stepmod2mn-1.59.jar <Publication-Index-XML-FileName> [--type <resource_docs or modules>]
----

e.g.

[source,sh]
----
java -Xss5m -jar target/stepmod2mn-1.58.jar publication/part1000/CR_PMI_5/publication_index.xml --type resource_docs
java -Xss5m -jar target/stepmod2mn-1.59.jar publication/part1000/CR_PMI_5/publication_index.xml --type resource_docs
----

NOTE: the Metanorma collection file 'metanorma.yml' will be saved in the 3 level up folder (usually, source repository's root folder).
Expand All @@ -168,42 +168,42 @@ NOTE: the Metanorma collection file 'metanorma.yml' will be saved in the 3 level

[source,sh]
----
java -jar target/stepmod2mn-1.58.jar <start folder to process xml maps files> --svg
java -jar target/stepmod2mn-1.59.jar <start folder to process xml maps files> --svg
----

e.g.

[source,sh]
----
java -jar target/stepmod2mn-1.58.jar data/resources --svg
java -jar target/stepmod2mn-1.59.jar data/resources --svg
----

=== Generate SVG images for the XML in the specified folder and sub-folders, and save them in the output folder:

[source,sh]
----
java -jar target/stepmod2mn-1.58.jar <start folder to process xml maps files> --svg [--output <Output-folder>]
java -jar target/stepmod2mn-1.59.jar <start folder to process xml maps files> --svg [--output <Output-folder>]
----

e.g.

[source,sh]
----
java -jar target/stepmod2mn-1.58.jar data/resources --svg --output schemas/
java -jar target/stepmod2mn-1.59.jar data/resources --svg --output schemas/
----

=== Generate SVG image for Express Imagemap XML and Image:

[source,sh]
----
java -jar stepmod2mn-1.58.jar --xml <Express Imagemap XML file path> --image <Image file name> [--svg <resulted SVG map file or folder>]
java -jar stepmod2mn-1.59.jar --xml <Express Imagemap XML file path> --image <Image file name> [--svg <resulted SVG map file or folder>]
----

e.g.

[source,sh]
----
java -jar stepmod2mn-1.58.jar --xml data\resource_docs\fundamentals_of_product_description_and_support\schema_diagexpg1.xml --image schema_diagexpg1.gif --svg schema_diagexpg1.svg
java -jar stepmod2mn-1.59.jar --xml data\resource_docs\fundamentals_of_product_description_and_support\schema_diagexpg1.xml --image schema_diagexpg1.gif --svg schema_diagexpg1.svg
----


Expand All @@ -223,7 +223,7 @@ Update version in `pom.xml`, e.g.:
----
<groupId>org.metanorma</groupId>
<artifactId>stepmod2mn</artifactId>
<version>1.58</version>
<version>1.59</version>
<name>STEPmod XML to Metanorma AsciiDoc converter</name>
----

Expand All @@ -234,8 +234,8 @@ Tag the same version in Git:

[source,xml]
----
git tag v1.58
git push origin v1.58
git tag v1.59
git push origin v1.59
----

Then the corresponding GitHub release will be automatically created at:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.metanorma</groupId>
<artifactId>stepmod2mn</artifactId>
<version>1.58</version>
<version>1.59</version>
<name>STEPmod XML to Metanorma AsciiDoc converter</name>
<packaging>jar</packaging>
<url>https://www.metanorma.org</url>
Expand Down
76 changes: 66 additions & 10 deletions src/main/resources/stepmod2mn.adoc.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,20 @@
<xsl:template name="insertParagraph">
<xsl:param name="text"/>
<xsl:param name="keep-with-next" select="'false'"/>
<!-- <xsl:value-of select="normalize-space($text)"/> -->
<xsl:apply-templates select="xalan:nodeset($text)" mode="linearize"/>
<xsl:variable name="paragraph">
<xsl:apply-templates select="xalan:nodeset($text)" mode="linearize"/>
</xsl:variable>
<xsl:choose>
<!-- for [SOURCE:...], see https://github.com/metanorma/stepmod2mn/issues/179#issuecomment-2083273335-->
<!-- <xsl:when test="starts-with($text,'[SOURCE:')">+++[+++<xsl:value-of select="substring($text,2)"/></xsl:when> -->
<xsl:when test="starts-with($paragraph,'[SOURCE:') and java:endsWith(java:java.lang.String.new($paragraph),']')">
<xsl:call-template name="parseSource">
<xsl:with-param name="text" select="$paragraph"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($paragraph,'[SOURCE:')">+++[+++<xsl:value-of select="substring($paragraph,2)"/></xsl:when>
<xsl:otherwise><xsl:copy-of select="$paragraph"/></xsl:otherwise>
</xsl:choose>
<xsl:if test="$keep-with-next = 'false'">
<xsl:text>&#xa;&#xa;</xsl:text>
</xsl:if>
Expand Down Expand Up @@ -1015,14 +1027,58 @@
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="text1">
<xsl:choose>
<!-- for [SOURCE:...], see https://github.com/metanorma/stepmod2mn/issues/179#issuecomment-2083273335-->
<xsl:when test="starts-with($text,'[SOURCE:')">+++[+++<xsl:value-of select="substring($text,2)"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$text"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="java:org.metanorma.RegExEscaping.escapeFormattingCommands($text1)"/>
<xsl:value-of select="java:org.metanorma.RegExEscaping.escapeFormattingCommands($text)"/>
</xsl:template>

<xsl:template name="parseSource">
<xsl:param name="text"/>
<!-- Example:
[SOURCE: ISO/TS 10303-4000:2023, 3.1.1, Modified – Notes to entry removed]
-->
<xsl:variable name="text1" select="substring-after(substring($text,1,string-length($text) - 1), '[SOURCE:')"/>
<xsl:variable name="standard_number">
<xsl:choose>
<xsl:when test="contains($text1,',')"><xsl:value-of select="normalize-space(substring-before($text1,','))"/></xsl:when>
<xsl:otherwise><xsl:value-of select="normalize-space($text1)"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="standard_number_without_year">
<xsl:choose>
<xsl:when test="contains($standard_number, ':')"><xsl:value-of select="substring-before($standard_number, ':')"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$standard_number"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- standard_number='<xsl:value-of select="$standard_number"/>'- -->
<xsl:variable name="standard_number_after" select="substring-after($text1,',')"/> <!-- Example: 3.1.1, Modified – Notes to entry removed -->
<xsl:variable name="section">
<xsl:choose>
<xsl:when test="contains($standard_number_after, ',')"><xsl:value-of select="normalize-space(substring-before($standard_number_after, ','))"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$standard_number_after"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- section='<xsl:value-of select="$section"/>' -->
<xsl:variable name="modified_" select="translate(normalize-space(substring-after($standard_number_after, ',')),'&#x2013;','-')"/>
<xsl:variable name="modified__">
<xsl:choose>
<xsl:when test="contains($modified_, 'Modified -')"><xsl:value-of select="substring-after($modified_, 'Modified -')"/></xsl:when>
<xsl:when test="contains($modified_, 'modified -')"><xsl:value-of select="substring-after($modified_, 'modified -')"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$modified_"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="modified" select="normalize-space($modified__)"/>
<!-- modified='<xsl:value-of select="$modified"/>' -->
<xsl:if test="$standard_number != ''">
<xsl:text>[.source]</xsl:text>
<br/>
<xsl:text>&lt;&lt;</xsl:text>
<!-- determine bibitem id -->
<xsl:variable name="bibliography_xml_document" select="document(concat($path, '../../../data/basic/bibliography.xml'))"/>
<xsl:variable name="bibitem_id" select="$bibliography_xml_document/bibitem.list/bibitem[stdnumber = $standard_number or stdnumber = $standard_number_without_year][1]/@id"/>
<xsl:value-of select="concat('bibitem_',$bibitem_id)"/>
<xsl:if test="$section != ''">, section <xsl:value-of select="$section"/></xsl:if>
<xsl:text>&gt;&gt;</xsl:text>
<xsl:if test="$modified != ''">, <xsl:value-of select="$modified"/></xsl:if>
</xsl:if>
</xsl:template>

<xsl:template name="repeat">
Expand Down

0 comments on commit 677ea9e

Please sign in to comment.