schemaLocation attribute dropped after XSL transformation

Discussion in 'XML' started by John, Oct 21, 2003.

  1. John

    John Guest

    I have an input document that contains a large base64 encoded
    document. This document also declares a schema location in the root
    element. I want to write an XSL stylesheet that makes an exact copy
    (including the namespace and schema location) of the input document
    except that it removes the base64 encoding and replaces it with the
    text 'REMOVED'.

    I have a stylesheet that does just that except that it drops the
    schemaLocation attribute. Where that attribute is supposed to be I
    get a ="" which then gives me an error when I parse the result because
    it is not well formed XML.

    I am using Xalan (not sure of the version) on Solaris with Java 1.3.1
    on SunOS 5.8

    Can anyone please tell me what I am doing wrong?

    Thanks much,
    -John

    INPUT DOCUMENT:
    <?xml version="1.0" encoding="UTF-8"?>
    <abc:DocumentInfo xmlns:abc="http://abc.com/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://abc.com/schema abc.xsd ">
    <BunchOfElements>....</BunchOfElements>
    <Attachment Encoding="BASE64"
    FileType="PDF">biglongbase64stringgoeshere</Attachment>
    </abc:DocumentInfo>

    XSL STYLESHEET:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:abc="http://www.abc.com/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    version="1.0">
    <xsl:eek:utput indent='yes' encoding='UTF-8' method='xml'/>
    <xsl:template match="/abc:TitleInfo">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="Attachment" priority="10">
    <Attachment>
    <xsl:attribute name="Encoding"><xsl:value-of
    select="./@Encoding" /></xsl:attribute>
    <xsl:attribute name="FileType"><xsl:value-of
    select="./@FileType" /></xsl:attribute>
    <xsl:text>REMOVED</xsl:text>
    </Attachment>
    </xsl:template>
    <xsl:template match="@*|node()" priority="1">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

    OUTPUT:
    <?xml version="1.0" encoding="UTF-8"?>
    <abc:DocumentInfo xmlns:abc="http://abc.com/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ="">
    <BunchOfElements>....</BunchOfElements>
    <Attachment xmlns:abc="http://www.abc.com/schema" Encoding="BASE64"
    FileType="PDF">REMOVED</Attachment>
    </abc:DocumentInfo>
     
    John, Oct 21, 2003
    #1
    1. Advertisements

  2. John

    Bob Foster Guest

    I don't see you are doing anything wrong. Here is what I got running your
    document and stylesheet through Saxon 7.5.2:

    <?xml version="1.0" encoding="UTF-8"?>
    <abc:DocumentInfo xmlns:abc="http://abc.com/schema"
    xsi:schemaLocation="http://abc.com/schema abc.xsd "
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <BunchOfElements>....</BunchOfElements>

    <Attachment Encoding="BASE64" FileType="PDF"
    xmlns:abc="http://www.abc.com/schema">REMOVED</Attachment>
    </abc:DocumentInfo>

    I assume this is pretty much what you expected.

    Bob Foster
     
    Bob Foster, Oct 22, 2003
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.