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

Discussion in 'XML' started by skippyd277@yahoo.com, Mar 13, 2008.

  1. Guest

    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
     
    , Mar 13, 2008
    #1
    1. Advertising

  2. Pavel Lepin Guest

    <> wrote in
    <>:
    > 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, too. </irony>

    > <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).

    --
    "...a Netscape engineer who shan't be named once passed a
    pointer to JavaScript, stored it as a string and later
    passed it back to C, killing 30..." --Blake Ross
     
    Pavel Lepin, Mar 14, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    1,123
    Victor Bazarov
    May 4, 2007
  2. Wabiloo
    Replies:
    1
    Views:
    833
    Martin Honnen
    Jan 25, 2008
  3. winterTTr
    Replies:
    2
    Views:
    363
    winterTTr
    Apr 29, 2009
  4. Asen Bozhilov

    Square bracket and dot notations?

    Asen Bozhilov, Jun 11, 2011, in forum: Python
    Replies:
    4
    Views:
    1,033
    Terry Reedy
    Jun 11, 2011
  5. Nalpo

    Object names with square bracket

    Nalpo, Aug 11, 2004, in forum: Javascript
    Replies:
    1
    Views:
    116
    lallous
    Aug 11, 2004
Loading...

Share This Page