Square bracket possible in href of xsl:result-document?

skippyd277

Usenet Archive
Joined
Mar 13, 2008
Messages
1
Reaction score
0
I'm attempting to create an OOXML spreadsheet rom an existing XML document. I have only one problem at this point and I can't seem to find a solution. The OOXML spec requires a file named [Content_Types].xml within the structure of the OOXML file. I can NOT get saxon to output any file name containing a square bracket. Everytime I try I get an error

Error at xsl:result-document on line ## of file:/path/to/file/ transform.xslt:
Exception thrown by OutputURIResolver: Invalid syntax for base URI:
Illegal character in
path at index ##: escape-uri(./ooxmlFileName/[Content_Types].xml)
Transformation failed: Run-time errors were reported

The relevant portions of my stylesheet is:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform" xmlns:xls="http://schemas.openxmlformats.org/spreadsheetml/ 2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/ 2006/relationships">

<xsl:eek:utput method="xml" indent="yes" encoding="UTF-8" standalone="yes"/>

<xsl:template match="/">
<xsl:variable name="contentTypesFileName">./<xsl:value-of select="/ path/to/ooxmlFileName"/>/[Content_Types].xml</xsl:variable>

<!-- [ContentTypes].xml -->
<xsl:result-document href="escape-uri({$contentTypesFileName})"> <xsl:element name="Types" namespace="http:// schemas.openxmlformats.org/package/2006/content-types"> <xsl:element name="Default" namespace="http:// schemas.openxmlformats.org/package/2006/content-types"> <xsl:attribute name="Extension">rels</xsl:attribute> <xsl:attribute name="ContentType">application/ vnd.openxmlformats-package.relationships+xml</xsl:attribute> </xsl:element> <xsl:element name="Default" namespace="http:// schemas.openxmlformats.org/package/2006/content-types"> <xsl:attribute name="Extension">xml</xsl:attribute> <xsl:attribute name="ContentType">application/xml</ xsl:attribute> </xsl:element> <xsl:element name="Override" namespace="http:// schemas.openxmlformats.org/package/2006/content-types"> <xsl:attribute name="PartName">/workbook.xml</xsl:attribute> <xsl:attribute name="ContentType">application/ vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml</ xsl:attribute> </xsl:element> <xsl:element name="Override" namespace="http:// schemas.openxmlformats.org/package/2006/content-types"> <xsl:attribute name="PartName">/sheet1.xml</xsl:attribute> <xsl:attribute name="ContentType">application/ vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml</ xsl:attribute> </xsl:element> </xsl:element> </xsl:result-document>

</xsl:template>

</xsl:stylesheet>

I'm using Saxon 9.0.0.2J with Java 1.6.0_05 on a fully updated Windows XP machine.

Suggestions will be greatly appreciated

Thanks,
Skippy
 

Pavel Lepin

Usenet Archive
Joined
Apr 20, 2007
Messages
263
Reaction score
0
Error at xsl:result-document on line ## of
file:/path/to/file/ transform.xslt:
Exception thrown by OutputURIResolver: Invalid syntax
for base URI:
Illegal character in
path at index ##:
escape-uri(./ooxmlFileName/[Content_Types].xml)
Transformation failed: Run-time errors were reported

href attribute on xsl:result-document should be a URI, not an XPath expression.
The relevant portions of my stylesheet is:

Nicely indented said:
<xsl:variable
name="contentTypesFileName">./<xsl:value-of select="/
path/to/ooxmlFileName"/>/[Content_Types].xml</xsl:variable>

Either escape your data at this point or just use
escape-uri-attributes="yes" on your xsl:result-document.
Saxon supports it I believe.
<!-- [ContentTypes].xml -->
<xsl:result-document
href="escape-uri({$contentTypesFileName})">

See above, this shouldn't be an XPath expression, just plain ole URI. So use a simple attribute value template, and escape-uri-attributes (or escape your filename before using it if this is somehow preferable to you).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,050
Messages
3,104,249
Members
248,133
Latest member
DujonT

Latest Threads

Top