#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Question How to get the relative path of an external entity


    Hello,

    I need a way to get the relative path of an external entity using xsl. Given the following xml:

    Code:
    <!NOTATION GIF SYSTEM "Graphical Interchange Format">  
    <!ENTITY mypicture SYSTEM "temp/me.gif" NDATA GIF>  
       
     ...  
       
    <graphic image="mypicture"></graphic>
    if I use the following xsl:

    Code:
    <xsl:value-of select="unparsed-entity-uri('image')"/>
    It returns the absolute path from where the transformation occurs. So if I run the transformation from c:\data\xyz\ then unparsed-entity-uri('image') returns c:\data\xyz\temp\me.gif, but I need the value temp/me.gif. How can I do that using xsl.

    XML that I need to transform is authored content and I cannot change that. I have to transform the xml to html and it is likely the absolute path will not match the document root, so such references will result in missing graphics when the HTML file is viewed.

    Any help is greatly appreciated.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,294
    Rep Power
    9400
    I don't think you can with basic XSLT 1.0. What are you using to do the transformations?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2011
    Posts
    42
    Rep Power
    4
    If you want to get the relative path, you have to use it in conjunction with resolve-uri(.) with some string manipulation. Like this.

    <xsl:variable name="abs-path" select="unparsed-entity-uri('image')" />
    <xsl:variable name="ref-path" select="replace(resolve-uri(.),'(^.*/)[^/]*$','$1')" />
    <xsl:variable name="rel-path" select="substring-after($abs-path,$ref-path)" />

    Now, the variable rel-path should hold the desired relative path to the image. (I assume the xsl-engine in use supports well the regex, replace() and substring-after().)

IMN logo majestic logo threadwatch logo seochat tools logo