Page 1 of 1

SQF adds invalid xmlns value in keyword

Posted: Sun Feb 28, 2016 10:45 am
by urbanrobots
Hello,

I am new to SQF, so my syntax may be incorrect.

I would like to replace plaintext strings with associated <keyword> elements.

For example, look for "product name" and replace it with "<keyword keyref="prod_name" /> ".

Using SQF, I tried this:

Code: Select all


<pattern>
<rule id="key_001" context="text()">
<report test="contains(., 'Product Name')" sqf:fix="replaceProdName" role="warning"
>key_002: Dolby Digital Plus has a key.</report>

<sqf:fix id="replaceProdName">
<sqf:description>
<sqf:title>Replace product name?</sqf:title>
</sqf:description>

<sqf:stringReplace regex="Product Name"><keyword keyref="prod_name"/>
</sqf:stringReplace>

</sqf:fix>
</rule>
</pattern>
However, this creates invalid XML output:

Code: Select all


<keyword xmlns="http://purl.oclc.org/dsdl/schematron" keyref="prod_name"/>
Which throws the error:
Attribute "xmlns" is not allowed to appear in element "keyword".
What am I doing wrong?

Thanks,
Nick

Re: SQF adds invalid xmlns value in keyword

Posted: Sun Feb 28, 2016 8:30 pm
by Patrik
I guess that <keyword> should have no namespace at all. But in your schematron file you have most likely declared at the root the default namespace to be "http://purl.oclc.org/dsdl/schematron":

Code: Select all

<schema xmlns="http://purl.oclc.org/dsdl/schematron" ...
Thus, it is applied to all elements without namespace prefix.

One option would be to use a namespace prefix for the schematorn elements:

Code: Select all

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" ...
.

Alternatively you can probably explicitly remove the inherited namespace from the keyword element:

Code: Select all

<keyword xmlns="" keyref="prod_name"/>
Patrik

Re: SQF adds invalid xmlns value in keyword

Posted: Mon Feb 29, 2016 11:38 am
by tavy
Hello,

Patrik response is correct, you need to set a namespace for the inserted element or use a prefix for the Schematron elements.

I always recommend to use a prefix for the Schematron elements. In this way you can insert elements from no namespace without caring about the namespace declaration.

To change the prefix you can use the contextual menu (right click) on an root element and pick Refactoring > Rename Prefix... to manually add a namespace prefix for all the elements from each of those namespaces. Simply introduce the new prefix name (e.g. sch) and select the option Rename current prefix in all document to add that namespace prefix for all the elements from that namespace found in the document.

Best Regards,
Octavian

Re: SQF adds invalid xmlns value in keyword

Posted: Tue Mar 01, 2016 7:54 pm
by urbanrobots
Thank you! That worked.