-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spurious Combinator error with default template #95
Comments
Thanks for the bug report. Union operations haven't been tested very thoroughly, so I'll add in this example to the test suite and then look at where the problem is. This will be in the XPath parser, pattern matching and expression transformation. |
The error for this example has now changed (using the "dev" branch): I see
with an input XSLT of
|
I tried splitting the templates to avoid the OR, but then My code is the same as in your docs for transforming XML, sans some variable name changes. |
Are you able to add a test case for this into the test suite? Send through a PR |
I've created a new branch for this issue - issue-95. I'll be pushing this to the repo shortly |
Sorry for the delay. Here's a simple repro for the combinator. I applied a workaround but getting a "union_expr" error in Repro code#![allow(dead_code)]
use xrust::{
parser::xml::parse, transform::context::StaticContextBuilder, trees::smite::RNode,
xslt::from_document, ErrorKind, Item, Node, SequenceTrait,
};
fn transform(template: &'static str) -> Result<String, xrust::Error> {
const XML: &str = r#"<?xml version="1.0"?>
<root>
<child id="1"/>
<child Id="2"/>
</root>
"#;
let xmldoc = Item::Node(make_from_str(XML)?);
let xsldoc = make_from_str(template)?;
let mut static_content = StaticContextBuilder::new()
.fetcher(|_| {
Err(xrust::Error::new(
ErrorKind::NotImplemented,
"not implemented",
))
})
.message(|_| Ok(()))
.parser(|_| {
Err(xrust::Error::new(
ErrorKind::NotImplemented,
"not implemented",
))
})
.build();
let mut ctx = from_document(xsldoc, None, make_from_str, |_| Ok(String::new()))?;
ctx.context(vec![xmldoc], 0);
ctx.result_document(RNode::new_document());
let xml = ctx.evaluate(&mut static_content)?;
Ok(xml.to_xml())
}
fn make_from_str(s: &str) -> Result<RNode, xrust::Error> {
let doc = RNode::new_document();
let _ = parse(doc.clone(), s, None)?;
Ok(doc)
}
#[test]
fn test_transform_combined() {
const XSL: &str = r#"
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
"#;
let actual = transform(XSL).unwrap();
println!("{actual}");
}
#[test]
fn test_transform_split() {
const XSL: &str = r#"
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
"#;
let actual = transform(XSL).unwrap();
println!("{actual}");
} |
The main problem is the union operator in the match pattern. I'm working on that now. Keep track of progress in the issue-95 branch. |
The <xsl:apply-templates select="node()"/> Same basic repro as I already pasted, but I commented out Repro: see BUGBUG line<xsl:stylesheet version="1.0"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" cdata-section-elements="style"/>
<xsl:template match="svg:svg">
<xsl:element name="svg" namespace="http://www.w3.org/2000/svg">
<xsl:apply-templates select="@*"/>
<!-- Use @media queries to stylize text for readability in different themes -->
<xsl:element name="style" namespace="http://www.w3.org/2000/svg">
<xsl:attribute name="style">text/css</xsl:attribute>
<xsl:text disable-output-escaping="yes"><![CDATA[
text { fill: #000000 }
polyline { fill: none; stroke: #000000 }
@media (prefers-color-scheme: dark) {
text { fill: #ffffff }
polyline { fill: none; stroke: #ffffff }
}
]]></xsl:text>
</xsl:element>
<!-- BUGBUG: <xsl:apply-templates select="node()"/> -->
</xsl:element>
</xsl:template>
<!-- Remove the "Input" label that overlaps Y axis labels -->
<!-- <xsl:template match="svg:text[normalize-space() = 'Input']"/> -->
<!-- Remove hardcoded colors I want to vary on @media queries -->
<!-- <xsl:template match="svg:text[@fill = '#000000']/@fill"/>
<xsl:template match="svg:polyline[@stroke = '#000000']/@stroke"/> -->
<!-- Split templates because of https://github.com/ballsteve/xrust/issues/95 -->
<!-- <xsl:template match="node()">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*">
<xsl:copy/>
</xsl:template> -->
</xsl:stylesheet> With that commented out, I get an Updated: I see that xrust/src/parser/xpath/functions.rs Line 73 in ca1d8ab
This has always been used in an identity template, but I see from https://developer.mozilla.org/docs/Web/XPath/Functions it's not actually defined as a function. If I change Stack trace
|
The issue-95 branch has the fix and has been promoted as a PR. |
An XSL template that includes the following "pass-through" rule will generate a spurious
Combinator
error inxslt::from_document
(using the sample code for the xrust:xslt module, simply with this added to the sample XSLT).The text was updated successfully, but these errors were encountered: