Project

Profile

Help

Support #6097

closed

How to create string sequence parameter for XSLT?

Added by Martin Honnen over 1 year ago. Updated over 1 year ago.

Status:
Duplicate
Priority:
Normal
Category:
Python API
Start date:
2023-06-26
Due date:
% Done:

0%

Estimated time:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Found in version:
SaxonC Languages:
SaxonC Platforms:
SaxonC Architecture:

Description

I am not sure whether I have hit a bug or am simply not finding the wrong way from the Python API to set an XSLT parameter to a sequence of strings; the Python code is e.g.

from saxonche import *

with PySaxonProcessor(license=False) as saxon_proc:
    xslt30_processor = saxon_proc.new_xslt30_processor()

    element_names = ['foo', 'foobar']

    xslt_param = PyXdmValue()

    for name in element_names:
        xslt_param.add_xdm_item(saxon_proc.make_string_value(name))

    xslt30_processor.set_parameter('cdata-tag-names', xslt_param)

    xslt30_processor.transform_to_file(source_file='sample2.xml', stylesheet_file='serialize-wrap-in-cdata1.xsl', output_file='result-sample2.xml')

XSLT is

<?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"
	exclude-result-prefixes="#all"
	expand-text="yes"
	version="3.0">

  <xsl:param name="cdata-tag-names" as="xs:string*" static="yes" select="'tag'"/>

  <xsl:mode on-no-match="shallow-copy"/>

  <xsl:output method="xml" _cdata-section-elements="{$cdata-tag-names}"/>

  <xsl:template _match="{$cdata-tag-names => string-join(' | ')}">
    <xsl:copy>{serialize(node())}</xsl:copy>
  </xsl:template>

</xsl:stylesheet>

XML is

<?xml version="1.0" encoding="utf-8" ?>
<root>
  <foo>
    some data
    <!-- some data2 -->
    <!-- some data2 -->
    some data
  </foo>
  <bar>
    some data
    <!-- some data2 -->
    <!-- some data2 -->
    some data
  </bar>
  <foobar>
    some data
    <!-- some data2 -->
    <!-- some data2 -->
    some data
  </foobar>
</root>

Error I get:

Traceback (most recent call last):
  File "C:\Users\marti\PycharmProjects\SaxonCHEWrapChildrenInCDATA\main2.py", line 15, in <module>
    xslt30_processor.transform_to_file(source_file='sample2.xml', stylesheet_file='serialize-wrap-in-cdata1.xsl', output_file='result-sample2.xml')
  File "python_saxon\saxonc.pyx", line 1276, in saxonche.PyXslt30Processor.transform_to_file
saxonche.PySaxonApiError: Unknown exception found

Files

main2.py (532 Bytes) main2.py Martin Honnen, 2023-06-26 15:44
sample2.xml (359 Bytes) sample2.xml Martin Honnen, 2023-06-26 15:44
serialize-wrap-in-cdata1.xsl (582 Bytes) serialize-wrap-in-cdata1.xsl Martin Honnen, 2023-06-26 15:44

Related issues

Is duplicate of SaxonC - Bug #6053: PydmNode object gets deleted before reuseClosedO'Neil Delpratt2023-05-26

Actions

Please register to edit this issue

Also available in: Atom PDF