Skip to content

Commit

Permalink
Improving runtime processor report XPL
Browse files Browse the repository at this point in the history
  • Loading branch information
wendellpiez committed Jan 7, 2025
1 parent eb8338a commit e8df93a
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions testing/PROCESSOR-REPORT.xpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,55 @@
type="ox:PROCESSOR-REPORT"
name="PROCESSOR-REPORT">

<p:output port="result"
<!-- This XProc delivers plain text as produced by the last step -->
<!-- If XML is wanted:
<p:output port="result-xml" pipe="" />
-->

<p:output port="basic" pipe="@basic"
serialization="map{'indent' : true(), 'omit-xml-declaration': true() }" />



<p:output port="plaintext" pipe="@pretty" serialization="map{'method': 'text' }" />

<!-- /prologue -->

<p:identity message="[PROCESSOR-REPORT] XPROC 3 Processor Report">
<!-- p:inline is implicit w/in p:with-input containing an element not in the p: namespace -->
<!-- Also note the whitespace in the XProc file comes with the XML tagging -->
<!-- we provide xml:space="preserve" which should inhibit munge the code -->
<p:with-input xml:space="preserve">
<PROCESSOR reporting="{ current-dateTime() }">
<product-name>{ p:system-property('p:product-name') }</product-name>
<product-version>{ p:system-property('p:product-version') }</product-version>
<vendor>{ p:system-property('p:vendor') }</vendor>
<vendor-uri>{ p:system-property('p:vendor-uri') }</vendor-uri>
<version>{ p:system-property('p:version') }</version>
<xpath-version>{ p:system-property('p:xpath-version') }</xpath-version>
<psvi-supported>{ p:system-property('p:psvi-supported') }</psvi-supported>
</PROCESSOR></p:with-input>
</p:identity>


<p:group name="basic" message="[PROCESSOR-REPORT] XPROC 3 Processor Report">
<p:identity>
<!-- p:inline is implicit w/in p:with-input containing an element not in the p: namespace -->
<!-- Also note the whitespace in the XProc file comes with the XML tagging -->
<p:with-input>
<PROCESSOR reporting="{ current-dateTime() }">
<product-name>{ p:system-property('p:product-name') }</product-name>
<product-version>{ p:system-property('p:product-version') }</product-version>
<vendor>{ p:system-property('p:vendor') }</vendor>
<vendor-uri>{ p:system-property('p:vendor-uri') }</vendor-uri>
<version>{ p:system-property('p:version') }</version>
<xpath-version>{ p:system-property('p:xpath-version') }</xpath-version>
<psvi-supported>{ p:system-property('p:psvi-supported') }</psvi-supported>
</PROCESSOR>
</p:with-input>
</p:identity>
<p:namespace-delete prefixes="ox"/>
</p:group>

<p:insert match="/PROCESSOR" position="last-child">
<!--Unlike XSLT, we use an absolute XPath, there is no relative context just a tree -->
<p:with-input port="insertion">
<p:inline xml:space="preserve"> <report-time>{ string(/*/@reporting) }</report-time>
</p:inline>
<p:inline>
<report-time>REPORTING AT { /*/@reporting => format-dateTime('[h01]:[m01] [P] on [FNn] [MNn] [D1o], [Y]') }</report-time>
</p:inline>
</p:with-input>
</p:insert>

<!-- Fancy XPath!
|| is a string concatenator
format-dateTime() is a function with a 'picture' argument -->
<p:string-replace match="/PROCESSOR/report-time/text()"
replace="'REPORTING AT ' || format-dateTime(.,
'[h01]:[m01] [P] on [FNn] [MNn] [D1o], [Y]')"/>

<!-- making labels explicit in content -->
<p:string-replace match="/PROCESSOR/*/text()"
replace="(local-name(parent::*), string(.)) => string-join(': ')"/>

<!-- Wiping markup by replacing the element with its string value -->
<p:string-replace match="/*" replace="string(.)"/>

<!-- trimming whitespace back to uniform length directly inside /*
so as to look nice as plain text -->
<p:string-replace name="pretty" match="/PROCESSOR/text()[matches(.,'^\s+$')]"
replace="'&#xA; '"/>

</p:declare-step>

0 comments on commit e8df93a

Please sign in to comment.