0

Good folks at stackoverflow... I am trying to create a XSLT transformation that will generate a Turtle file (RDF related). Part of that involves output of prefixed namespaces, something like this:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:sap="http://www.sap.com/sapxsl"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:sap_coda="http://www.sapmantics.com/sap_coda#"
    version="1.0">

  <xsl:strip-space elements="*"/>

  <xsl:template match="/">
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>' .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
...

When I try to apply the transformation, I get:

$ xsltproc zcoda_ttl_v02x.xslt zcoda_data_v02.xml > zcoda_data_v02x.ttl | x.txt
zcoda_ttl_v02x.xslt:10: namespace error : Failed to parse QName 'http:'
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>' .
                    ^
zcoda_ttl_v02x.xslt:10: parser error : error parsing attribute name
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>' .
                    ^
zcoda_ttl_v02x.xslt:10: parser error : attributes construct error
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>' .
                    ^
zcoda_ttl_v02x.xslt:10: parser error : Couldn't find end of Start Tag http: line 10
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>' .

So, I am at a loss here. The Turtle output that I seek contains many of these cases. Is there some way to stop the processor and just consider the http... as plain data (like the CDATA option in xml) ? Thanks, John

Borodin
  • 126,100
  • 9
  • 70
  • 144
johnaco
  • 175
  • 1
  • 3
  • 16

2 Answers2

0

You can enclose the http stuff in an xsl:text i guess:

 <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                xmlns:sap="http://www.sap.com/sapxsl" 
                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
                xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
                xmlns:sap_coda="http://www.sapmantics.com/sap_coda#" 
                version="1.0">

  <xsl:strip-space elements="*"/>

  <xsl:template match="/">
@prefix rdfs: <xsl:text><![CDATA[<http://www.w3.org/2000/01/rdf-schema#>]]></xsl:text>
rene
  • 41,474
  • 78
  • 114
  • 152
0

Use entities:

@prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;' .
@prefix owl: &lt;http://www.w3.org/2002/07/owl#&gt; .
@prefix dc: &lt;http://purl.org/dc/elements/1.1/&gt; .
Borodin
  • 126,100
  • 9
  • 70
  • 144
  • I did try this, but my output now contains < and >, which is not my intent. I need to have the output contain the actual < and > symbols. – johnaco Apr 19 '13 at 14:54
  • 1
    @johnaco: Either you're output is *text*, in which case you want `` in your stylesheet, or it is *XML*, when literal `<` and `>` are invalid in PCDATA and you have to use the entities. A third possibility is that you're using CDATA, but please tell us if so. – Borodin Apr 19 '13 at 15:33
  • Very nice. That is what was missing - the output method="text". With that, both methods described - using &lt > or using the CDATA approach works as desired. Thank you! – johnaco Apr 19 '13 at 19:46