Пример #1
0
    def test_output_detection_default_fallback(self):
        """
        Test output detection for a stylesheet without output declaration
        """

        stylesheet = defusedxml_fromstring("""
            <xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/TR/xhtml1/strict">
            </xsl:stylesheet>
        """)

        result = xsl.XslOutputMethodDetection().detect(stylesheet)
        self.assertEqual(result, "xml")
Пример #2
0
    def test_output_detection_explicit_text(self):
        """
        Test output detection for a stylesheet which has method set to text
        """

        stylesheet = defusedxml_fromstring("""
            <xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/TR/xtext1/strict">
                <xsl:output method="text" indent="yes" />
            </xsl:stylesheet>
        """)

        result = xsl.XslOutputMethodDetection().detect(stylesheet)
        self.assertEqual(result, "text")
Пример #3
0
    def _transform(self, item):
        if not self.doc:
            self.doc = etree.parse(self.path)
            yield

        if not self.transformer:
            self.transformer = etree.XSLT(self.doc)

        for oid in item['inserts']:
            if self.key:
                markup = item['data'][oid][self.key]
                doc = defusedxml_fromstring(markup)
            else:
                doc = self.doc

            params = self._extract_params(item['data'][oid])
            markup = bytes(self.transformer(doc, **params))

            if self.encoding is not None:
                markup = markup.decode(self.encoding)

            item['data'][oid][self.destkey] = markup

            yield