|
From: Schimon J. <sc...@fe...> - 2025-07-25 08:38:54
|
Greetings.
I am answering to myself.
This code works, and the results are good, despite the lack of the
desired element </xsl:text>.
--- BEGIN PYTHON CODE ---
from docutils.core import publish_parts
import lxml.etree as ET
class UtilityRst:
def convert_to_html(rst_content_str):
html_content_str = publish_parts(source=rst_content_str,
writer_name="html")
return html_content_str["fragment"]
class ParserXml:
def append_xhtml_to_xslt(filepath_xslt, filepath_rst):
document_xslt = ET.parse(filepath_xslt)
rst_content_str = open(filepath_rst, mode="r").read()
xhtml_content_str = UtilityRst.convert_to_html(rst_content_str)
lines = rst_content_str.split("\n")
for line in lines:
if line.startswith(".. xpath"):
expression_xpath = line.split(": ")[1]
break
element_xml = document_xslt.xpath(expression_xpath)
if element_xml:
subelement = ET.fromstring(xhtml_content_str)
element_xml[0].append(subelement)
document_xslt.write(filepath_xslt, pretty_print=True)
--- END PYTHON CODE ---
This code will be featured in project Rivista (Vivista).
https://git.xmpp-it.net/sch/Rivista (Current brand)
https://git.xmpp-it.net/sch/Vivista (Future brand)
Kind regards,
Schimon
On Thu, 24 Jul 2025 04:22:15 +0300
Schimon Jehudah via Docutils-users
<doc...@li...> wrote:
> Greetings.
>
> I am working to create a publishing system which is enntirely based on
> XML (Atom Syndication Format) with XSLT stylesheets to transform XML
> to XHTML.
>
>
> Preface
> -------
>
> XSLT stylesheets are utilized instead of templating engines (e.g.
> Jinja2), in order to generalize theming systems for CMS and other
> types of publishing platforms.
>
> However, modifying of XSLT for navigation links is essential for this
> idea to succeed.
>
>
> Concern
> -------
>
> While adding plain text, as is, should be workable, I would rather
> enclose text within tag </xsl:text>, if possible.
>
> <xsl:text>This an</xsl:text>
> <xsl:text> </xsl:text>
> <a href="?xml">Atom Syndication Format</a>
> <xsl:text> </xsl:text>
> <xsl:text>document which was transformed to HTML with</xsl:text>
> <xsl:text> </xsl:text>
> <a href="/about/xslt">XSLT stylesheets</a>
>
>
> Questions
> ---------
>
> Is this possible to do with docutils?
>
> Would it applicable to ask for such feature?
>
>
> Kind regards,
> Schimon
>
>
> _______________________________________________
> Docutils-users mailing list
> Doc...@li...
> https://lists.sourceforge.net/lists/listinfo/docutils-users
>
> Please use "Reply All" to reply to the list.
|