alexmilowski / green-turtle

An RDFa 1.1. implementation for browsers.
MIT License
56 stars 20 forks source link

Support namespaces #2

Open AlexanderWillner opened 9 years ago

AlexanderWillner commented 9 years ago

Description: The library doesn't seem to handle RDFa if it's not in the default name space. Version: Latest (today / 1.3.0)

Steps that will reproduce the problem?

  1. Add a prefix to an attribute (e.g. test 0330)
  2. Run the test

What is the expected result? Test should pass.

What happens instead? Test fails.

Possible workaround: ?

Any additional information:

<?xml version="1.0" encoding="UTF-8"?>
<root prefix="dcterms: http://purl.org/dc/terms/ xsd: http://www.w3.org/2001/XMLSchema#"
xmlns:foo="http://www.w3.org/1999/xhtml"
>
<head>
   <title>Test 0330</title>
</head>
<body lang="en">
  <div foo:property="dc:date" foo:datatype="xsd:date">2010-11-12</div>
</body>
</root>
$ rapper -qi rdfa -o ntriples 0330.xml > 0330.n3
$ sparql --data="0330.n3" --query="0330.sparql"
Ask => Yes
$
alexmilowski commented 9 years ago

There is no expectation that XML, it its most generic senses as a host language, use prefixed attributes. Test 0330 for XML does not contain namespaces RDFa attributes (see http://rdfa.info/test-suite/test-cases/rdfa1.1/xml/0330.xml).

Green Turtle passes the test suite and, in particular, this test. It does not support the ability to process host languages where the attributes are in the XHTML namespace. Although that feature could be added, it isn't planned at this time.

AlexanderWillner commented 9 years ago

Might be a misunderstanding. I just used Test 0330 as an arbitrary example to introduce a namespace. I was referring to the following sentence in the "RDFa Core 1.1 - Second Edition" document: "When a Host Language does not use the attributes in 'no namespace', they must be referenced via the XHTML Namespace (http://www.w3.org/1999/xhtml)." When embedding RDFa in existing XML documents, this is sometimes needed.

But your summary seems to nail it down: while the specification allows namespaces, Green Turtle does not support them, yet. Thanks.

alexmilowski commented 9 years ago

Actually, the specification says that "When a Host Language does not use the attributes in 'no namespace' ..." and XML, as a generic host language, allows for attributes in the no namespace. As such, the clause does not apply.

If there was an XML vocabulary that forbid them or forbid any extra attributes without a namespace, then you would want a processor that supported such a mode. For example, I couldn't add RDFa attributes to the XProc vocabulary because it forbids any attributes without a namespace except its own. As such, to add RDFa to XProc, I would need to use the XHTML namespace with the attributes. As such, the Green Turtle processor can't process such a situation.

As I said, it would be possible to add that support. In RDFaProcessor.js you would have to override setContext() to detect the vocabulary. Unfortunately, the code would need to be refactored to use a table of attribute namespaces as the names are just literals in the various places.

Not a huge amount of work but I can't get to this now. I'll keep this open because such refactoring should be done anyway.

I'd be happy to accept a patch. ;)