Skip to content

Commit

Permalink
Option to do xsl transformation before or after matching xpath
Browse files Browse the repository at this point in the history
  • Loading branch information
mshroom committed Mar 8, 2024
1 parent 82905b9 commit bcb844d
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/RecordManager/Base/Command/Records/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ class Export extends AbstractBase
*/
protected $deduped = 0;

/**
* Do not add a root element around the XML
*
* @var ?bool
*/
protected $noRoot;

/**
* Configuration file for optional XSL transformation to be applied to records
*
Expand All @@ -258,11 +265,11 @@ class Export extends AbstractBase
protected $xslTransformation;

/**
* Do not add a root element around the XML
* Apply XSL transformation before trying to match XPath expression
*
* @var ?bool
*/
protected $noRoot;
protected $transformBeforeXPath;

/**
* Callback to support the iterateRecords method of the database object.
Expand Down Expand Up @@ -293,7 +300,7 @@ public function iterateRecordsCallback($record): bool
}
}
$xmlStr = $metadataRecord->toXML();
if ($propertiesFile = $this->xslTransformation) {
if ($this->transformBeforeXPath && $propertiesFile = $this->xslTransformation) {
$transformation = new XslTransformation(
RECMAN_BASE_PATH . '/transformations',
$propertiesFile
Expand Down Expand Up @@ -371,6 +378,13 @@ public function iterateRecordsCallback($record): bool
$xmlStr = $xml->saveXML();
}
}
if (!$this->transformBeforeXPath && $propertiesFile = $this->xslTransformation) {
$transformation = new XslTransformation(
RECMAN_BASE_PATH . '/transformations',
$propertiesFile
);
$xmlStr = $transformation->transform($xmlStr);
}
++$this->count;
if ($record['deleted']) {
if ($this->deletedFile) {
Expand Down Expand Up @@ -556,6 +570,11 @@ protected function configure()
null,
InputOption::VALUE_REQUIRED,
'Configuration file for optional XSL transformation to be applied to records'
)->addOption(
'xslt-first',
null,
InputOption::VALUE_NONE,
'Apply XSL transformation before trying to match XPath expression'
);
}

Expand Down Expand Up @@ -596,8 +615,9 @@ protected function collectArgumentsAndOptions(InputInterface $input): void
}
$this->additionalNamespaces[$parts[0]] = $parts[1];
}
$this->xslTransformation = $input->getOption('xslt');
$this->noRoot = ($input->getOption('no-root') && ($this->batchSize == 1 || $this->singleId));
$this->xslTransformation = $input->getOption('xslt');
$this->transformBeforeXPath = $input->getOption('xslt-first');
}

/**
Expand Down

0 comments on commit bcb844d

Please sign in to comment.