0

I am working on an XSL Stylsheet to view FOAF Files and wan't to show the names and (if available) pictures of the people a person knows.

Since they may change their picture or name I would like to get this information from their Profile instead of manually adding them to mine. As I gather, the document() function loads a xml file and allows to get information from there but whatever syntax I use, I don not seem to get any information.

I have included below several ways I tried to get the name of a contact, but none of these return any data (some return an error, as is noted in the comments)

    <div id="contacts">
        <ul>
        <xsl:for-each select="rdf:RDF/foaf:Person/foaf:knows">
            <xsl:choose>
                <xsl:when test="foaf:Person/rdfs:seeAlso">
                    <li>
                        <xsl:variable name="url" select="foaf:Person/rdfs:seeAlso/@rdf:resource" /> <!--works!-->
                        <xsl:value-of select="$url"/> <!-- the url is correct-->
                        <xsl:copy-of select="document($url)" /> <!-- XML Parsing Error: no element found Location: http://www.someurl.com/me.rdf Line Number 1, Column 1:-->
                        <xsl:value-of select="document($url)/rdf:RDF/foaf:Person/foaf:name[@value=$value]"/> <!--no result-->
                        <xsl:value-of select="document($url)/rdf:RDF/foaf:Person/foaf:name"/> <!--no result-->
                        <xsl:value-of select="document(foaf:Person/rdfs:seeAlso/@rdf:resource)/rdf:RDF/foaf:Person/foaf:name"/><!--no result-->
                        <xsl:value-of select="document(foaf:Person/rdfs:seeAlso/@rdf:resource)/rdf:RDF/foaf:Person/foaf:name[@value=$value]"/><!--no result-->
                    <a>
                        <xsl:attribute name="href"> 
                            <xsl:value-of select="foaf:Person/rdfs:seeAlso/@rdf:resource"/></xsl:attribute><xsl:text>X</xsl:text>
                        <xsl:value-of select="document($url)/rdf:RDF/foaf:Person/foaf:name"/> <!--nor result-->
                    </a>
                    <!-- A link of an X is displayed, linking to the right foaf-profile-->
                    </li>
                </xsl:when>
                <xsl:otherwise>
                    <li><xsl:value-of select="foaf:Person/foaf:name"/></li>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
        </ul>
    </div>

My theory is, that for security reasons one is not allowed to load data from other XML-Files on the net (these files are on some server somewhere on the net, not locally). If this is the case, is there a way to circumvent this and signal the system that it is allowed to load this file?

Thanks in advance for your help.

Lukas Ruge
  • 2,204
  • 3
  • 30
  • 42
  • Check the error console of your browser if that is client-side XSLT. I think it should show an error or at least a warning if a `document()` call fails due to security restrictions. Is that code still part of a Mozilla extension? Extension code should normally not be subjected to the same origin policy. As for allowing a cross-domain request, the server can allow it, see https://developer.mozilla.org/en/HTTP_access_control, but I am not sure XSLT document() calls support that already. – Martin Honnen Jun 21 '11 at 16:29
  • I did a test with Firefox 4.0.1, it allows cross-domain XSLT `document()` calls if the server allows it by sending the response header described in the document I linked to in my previous comment. – Martin Honnen Jun 21 '11 at 16:46
  • Can you post a sample of the XML input including the xml that is found at your `$url`? – cordsen Jun 22 '11 at 02:26
  • It is not part of the extension (but I think it might become part of it) ritght now it's just an XSL file on a webserver that is called from the extension to format the rdf file. – Lukas Ruge Jun 22 '11 at 10:31
  • Now I tried puting the xsl file into the firefox-extension, the problems however are identical – Lukas Ruge Jun 22 '11 at 10:42
  • Right now what I get from the error console of my browser is just "no element found" even though the url is correct. The problem might be that no data is transmitted (that somehow I cannot access the file) or that my syntax is wrong so that I should access the data diferently. – Lukas Ruge Jun 22 '11 at 11:39

1 Answers1

0

Cross domain XSLTs always have some issues. Sometimes they are not working at all or just in specific browsers.

I found a bug report for firefox. It seems that cross-domain document() is not allowed: https://bugzilla.mozilla.org/show_bug.cgi?id=353886

However there seems to be workaround using one of this Javascript libraries: JQuery transform or Sarissa.

For a detailed answer look here:
XSLT using JavaScript Example

Community
  • 1
  • 1
therealmarv
  • 3,692
  • 4
  • 24
  • 42