Using XSL where source docuement has DOCTYPE/DTD declaration

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ken Larson

    Using XSL where source docuement has DOCTYPE/DTD declaration

    I have a question about using XSL to extract information from an SVG
    (XML) file that has a DOCTYPE/DTD declaration. I am able to do this
    successfully if I write my own SVG files without such a declaration.

    However, I would like to extract some parts of an SVG file exported by
    illustrator. When I try this, my XSL file is no longer able to access
    the nodes in the SVG document properly - somehow related to the
    DOCTYPE/DTD declaration.

    My SVG is as follows (I stripped out all of the actual contents for
    testing). If I remove the entire DOCTYPE/DTD declaration, everything
    works fine.

    <?xml version="1.0" encoding="utf-8"?>
    <!-- Generator: Adobe Illustrator 11.0, SVG Export Plug-In . SVG
    Version: 6.0.0 Build 78) -->
    <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
    "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
    <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
    <!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
    <!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrato r/10.0/">
    <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
    <!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
    <!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacemen t/1.0/">
    <!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
    <!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNa mespace/1.0/">
    <!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">
    <!ENTITY ns_svg "http://www.w3.org/2000/svg">
    <!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
    ]>
    <svg>
    <style type="text/css">
    </style>
    </svg>

    My XSL follows. It simply prints "Found SVG" if it finds the svg node.
    Like I said, it finds it if the SVG doesn't have the whole DOCTYPE/DTD
    declaration. But if I leave the DOCTYPE/DTD declaration in, it only
    finds the root.

    <?xml version="1.0"?>
    <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:template match="/">
    Found Root

    <xsl:apply-templates select="svg" />

    </xsl:template>

    <xsl:template match="svg">
    Found SVG
    </xsl:template>

    Thanks,

    Ken Larson
  • Philippe Poulard

    #2
    Re: Using XSL where source docuement has DOCTYPE/DTD declaration

    Ken Larson wrote:[color=blue]
    > I have a question about using XSL to extract information from an SVG
    > (XML) file that has a DOCTYPE/DTD declaration. I am able to do this
    > successfully if I write my own SVG files without such a declaration.
    >
    > However, I would like to extract some parts of an SVG file exported by
    > illustrator. When I try this, my XSL file is no longer able to access
    > the nodes in the SVG document properly - somehow related to the
    > DOCTYPE/DTD declaration.
    >
    > My SVG is as follows (I stripped out all of the actual contents for
    > testing). If I remove the entire DOCTYPE/DTD declaration, everything
    > works fine.
    >
    > <?xml version="1.0" encoding="utf-8"?>
    > <!-- Generator: Adobe Illustrator 11.0, SVG Export Plug-In . SVG
    > Version: 6.0.0 Build 78) -->
    > <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
    > "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
    > <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
    > <!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
    > <!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrato r/10.0/">
    > <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
    > <!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
    > <!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacemen t/1.0/">
    > <!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
    > <!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNa mespace/1.0/">
    > <!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">
    > <!ENTITY ns_svg "http://www.w3.org/2000/svg">
    > <!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
    > ]>
    > <svg>
    > <style type="text/css">
    > </style>
    > </svg>
    >
    > My XSL follows. It simply prints "Found SVG" if it finds the svg node.
    > Like I said, it finds it if the SVG doesn't have the whole DOCTYPE/DTD
    > declaration. But if I leave the DOCTYPE/DTD declaration in, it only
    > finds the root.
    >
    > <?xml version="1.0"?>
    > <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    >
    > <xsl:template match="/">
    > Found Root
    >
    > <xsl:apply-templates select="svg" />
    >
    > </xsl:template>
    >
    > <xsl:template match="svg">
    > Found SVG
    > </xsl:template>
    >
    > Thanks,
    >
    > Ken Larson[/color]

    hi,

    as mentionned in the dtd :

    For SVG 1.0:

    Namespace:



    <!ATTLIST svg
    xmlns CDATA #FIXED "http://www.w3.org/2000/svg"

    svg is in a namespace

    your xslt has not been designed to match svg elements, but can only
    match an element called "svg" not bound to the svg uri

    you *must* defined a prefix to use qualified names in xslt :

    this will work :

    <?xml version="1.0"?>
    <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
    xmlns:svg="http ://www.w3.org/2000/svg"
    version="1.0">

    <xsl:template match="/">
    Found Root

    <xsl:apply-templates select="svg:svg " />

    </xsl:template>

    <xsl:template match="svg:svg" >
    Found SVG
    </xsl:template>

    remember that unprefixed attributes are not bound to any namespace, so
    use xpath expressions like this :
    /svg:svg/svg:style/@type
    instead of :
    /svg:svg/svg:style/@svg:type

    --
    Cordialement,

    ///
    (. .)
    -----ooO--(_)--Ooo-----
    | Philippe Poulard |
    -----------------------

    Comment

    Working...