extractXSFcontent.xsl

extractXSFcontent.xsl - removing levels or layers (+segments) from an XSF instance

Version 18.02.2011, 17:41 (GMT)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU GNU Lesser General Public License for more details.

You should have received a copy of the GNU GNU Lesser General Public License along with this program (file 'lgpl-3.0.txt'). If not, see http://www.gnu.org/licenses/.

Making it simple to delete or extract parts of the XStandoff annotation the stylesheet extractXSFcontent.xsl can be applied to an XStandoff file. During the transformation call one has to name the ID of the element (xsf:annotation, xsf:level or xsf:layer) to be deleted or extracted in the form of the value of the corresponding parameter remove-ID or extract-ID. The matching element is removed/extracted from the XStandoff file and the list of segments is updated, i.e. the segments which solely were referenced by descendant elements of the mentioned element are excluded. This, admittedly, again leads to a reorganzation of the segments since these by default get a continuous numbering.

Similar to the usage of the mergeXSF.xsl stylesheet the reorganization of the segments can be disabled by the stylesheet parameter keep-segments. The value '1' lets the stylesheet keep the old segments, but without those only referenced by descendant elements of the deleted element.

Input XML file: XSF instance

Stylesheet parameters:

  • remove-ID (xs:string) - ID of the element (<xsf:annotation>, <xsf:level> or <xsf:layer>) to be removed (with descendants)
  • extract-ID (xs:string) - ID of the element (<xsf:annotation>, <xsf:level> or <xsf:layer>) to be extracted and returned in a new XStandoff instance
  • keep-segments (xs:boolean) - determines if segments and corresponding IDs are to be kept or reorganized (default: false - reorganization)

Execution via command line (XSLT processor Saxon9): java -jar saxon9.jar [optional Saxon Parameters] -o [XSF output filename] [XSF input filename] extractXSFcontent.xsl [extract-ID | remove-ID]=[id of level/layer] [optional Stylesheet Parameters]

Author:
Daniel Jettka; daniel.jettka@uni-bielefeld.de; Project Sekimo (A2), DFG Research Group 437
Copyright:
GNU Lesser General Public License, see below for details

Parameters Summary

xs:boolean extract-ID - source

ID of the level or layer to be extracted

xs:boolean keep-segments - source

Should segments and corresponding IDs be kept or reorganized? Default value is false

xs:string? remove-ID - source

ID of the level or layer to be removed

xs:boolean return-removed - source

Should removed layer/level be output in additional new XSF instance? Default is false

Variables Summary

Storing element which is to be deleted from the annotation.

Containing the segments which are referenced by the elements which are to be deleted/extracted from the annotation (descendants of $elem-by-id-in-stylesheet-param).

Storing the sequence of segments which shall be transferred to the new segment list.

xs:string primary-data - source

Textual content of inline annotation (primary data)

Root node for referencing.

Keys Summary

elem-by-segRef (match: *, use: @xsf:segment) - source

Find elements by their segment reference @xsf:segment

seg-by-ID (match: xsf:segment, use: @xml:id) - source

Find <xsf:segement> by the value of their attribute @xml:id

Match Templates Summary

Initial template with several tasks → see detailed description

Explicitly ignoring text nodes.

Shallow copy of the matched element and application of further templates.

Explicitly ignoring the <xsf:level> being or containing the element which is to be deleted and the <xsf:layer> being the one to be deleted.

Deep copy of the matched elements.

Creation of a new <xsf:segmentation> containing the segments which are present in the remaining layers and levels.

Named Templates Summary

copyAnnotations (param: xs:string level) - source

Copying annotation elements from levels or layers while returning the new segment references.

Returning of the deleted annotation in a separate XSF file.

Functions Summary

xs:boolean bool:compare2paramID (param: xs:string? IDxs:string comparation) - source

Comparison of the provided $ID to the ($remove-id|$extract-ID).

element(xsf:segment)* elem:copy-segments-with-new-ID (param: element(xsf:segment)* segments) - source

Copying segments and creating new IDs

element()* elem:sort-segments (param: element()* segments) - source

Sorting of segments by their @start and @end

Returning messages about stylesheet parameters

Parameters Detail

xs:boolean extract-ID - source

ID of the level or layer to be extracted

xs:boolean keep-segments - source

Should segments and corresponding IDs be kept or reorganized? Default value is false

xs:string? remove-ID - source

ID of the level or layer to be removed

xs:boolean return-removed - source

Should removed layer/level be output in additional new XSF instance? Default is false

Variables Detail

Storing element which is to be deleted from the annotation.

Containing the segments which are referenced by the elements which are to be deleted/extracted from the annotation (descendants of $elem-by-id-in-stylesheet-param).

Storing the sequence of segments which shall be transferred to the new segment list.

xs:string primary-data - source

Textual content of inline annotation (primary data)

Root node for referencing.

Keys Detail

elem-by-segRef (match: *, use: @xsf:segment) - source

Find elements by their segment reference @xsf:segment

seg-by-ID (match: xsf:segment, use: @xml:id) - source

Find <xsf:segement> by the value of their attribute @xml:id

Match Templates Detail

Initial template with several tasks → see detailed description

Tasks fulfilled by this initial template:

  1. Returning of messages containing information about provided stylesheet parameters
  2. Applying other templates
  3. Returning the deleted element in a separate XSF file if desired

Explicitly ignoring text nodes.

Shallow copy of the matched element and application of further templates.

Explicitly ignoring the <xsf:level> being or containing the element which is to be deleted and the <xsf:layer> being the one to be deleted.

Deep copy of the matched elements.

Creation of a new <xsf:segmentation> containing the segments which are present in the remaining layers and levels.

Named Templates Detail

copyAnnotations (param: xs:string level) - source

Copying annotation elements from levels or layers while returning the new segment references.

Parameters:
xs:string level - If value is 'new' then the segment references from the $newSegments are used otherwise those from $removedSegments.

Returning of the deleted annotation in a separate XSF file.

Functions Detail

xs:boolean bool:compare2paramID (param: xs:string? IDxs:string comparation) - source

Comparison of the provided $ID to the ($remove-id|$extract-ID).

Parameters:
xs:string? ID - String to be compared to ($remove-id|$extract-ID).
xs:string comparation - Operator serving for equation: '!=' or '='
element(xsf:segment)* elem:copy-segments-with-new-ID (param: element(xsf:segment)* segments) - source

Copying segments and creating new IDs

Parameters:
element(xsf:segment)* segments - Segments that shall be copied with their new ID.
element()* elem:sort-segments (param: element()* segments) - source

Sorting of segments by their @start and @end

Parameters:
element()* segments - Segments which shall be sorted.

Returning messages about stylesheet parameters