[oXygen-user] Feature request: Validation for linked images in SVG paths
Alex Jitianu
alex_jitianu at sync.ro
Wed Jul 31 03:01:24 CDT 2013
Hi Matt,
You're right about the context. I've probably accidentally removed the
ends-with(@href, '.svg') part. You should also integrate Wendell
suggestions (thank you Wendell) as they are better and much cleaner than
what I came up with.
Best regards,
Alex
On 30-Jul-13 6:13 PM, KAATMAN Matthew wrote:
>
> It's close Alex.
>
> I think it's testing non-SVG images now so it leads to two errors for
> each image in the document. I think maybe I need to go back to the
> previous rule context.
>
> <rule context="image[ends-with(@href, '.svg')]"
> <mailto:image[ends-with%28 at href,%27.svg%27%29]>> or maybe multiple
> rule contexts.
>
> System ID:
> C:\dita\en\products\simon\images\Shock_Tilt_Watch_Indicators.JPG
>
> Engine name: ISO Schematron (XSLT 2.0)
>
> Severity: fatal
>
> Description: Invalid byte 1 of 1-byte UTF-8 sequence.
>
> Type: XML validation
>
> Start location: 1:1
>
> System ID: C:\dita\en\products\simon\service\VerifyContents.dita
>
> Engine name: ISO Schematron (XSLT 2.0)
>
> Severity: error
>
> Description: The SVG file can't be loaded
> file:/C:/dita/en/products/simon/images/Shock_Tilt_Watch_Indicators.JPG
> ($svgExists) [assert]
>
> Type: XML validation
>
> Start location: 24:56
>
> This is a great working example for me to play with. I'll report back
> if I can get it straightened out.
>
> Thanks!
> Matt
>
> *From:*Alex Jitianu [mailto:alex_jitianu at sync.ro]
> *Sent:* Tuesday, July 30, 2013 9:35 AM
> *To:* KAATMAN Matthew
> *Cc:* oxygen-user at oxygenxml.com
> *Subject:* Re: [oXygen-user] Feature request: Validation for linked
> images in SVG paths
>
> Hello Matt,
>
> 1. The odd line is related to the fact that when validating with a
> Schematron file under the hood the Schematron is transformed in XSLT
> and that XSLT is applied on the document. The reported error line is
> inside that intermediate XSLT and unfortunately I don't think there is
> a round trip to get the real location in the Schematron file.
>
> 2. I believe the NullPointerException is a side effect of the fact
> that I didn't consider the fact that the SVG file is also referred
> relatively in the DITA document. As a result the SVG will not get
> located and parsed by the document() function and later on exists()
> function will break. In the example below I've added the resolve-uri()
> function to compute the SVG document location.
>
> 3. In the example below I've changed a bit the assert XPath to ignore
> the href values that start with 'data'. You should also take into
> account the fact that the SVG can contain multiple image elements.
> Perhaps you could assert it more elegantly than this but here a
> possible solution:
>
> <schema
> xmlns="http://purl.oclc.org/dsdl/schematron"
> <http://purl.oclc.org/dsdl/schematron>
> queryBinding="xslt2"
> xmlns:exslt="http://expath.org/ns/file" <http://expath.org/ns/file>>
> <ns uri="http://expath.org/ns/file" <http://expath.org/ns/file>
> prefix="exslt"/>
> <pattern>
> <rule context="image">
> <let name="svgDocument" value="document(resolve-uri(@href,
> base-uri()))" />
> <let name="svgExists" value="exists($svgDocument)"/>
> <assert test="$svgExists">The SVG file can't be loaded
> <value-of select="resolve-uri(@href, base-uri())"/></assert>
>
> <let name="realImages" value="$svgDocument//*:image/@*:href"/>
> <!-- If the SVG file can't be loaded or the SVG points to
> an embeded image SKIP IT. -->
> <let name="testImages" value="for $realImage in
> $realImages return if (not($svgExists) or starts-with($realImage,
> 'data')) then true() else exslt:exists(resolve-uri($realImage,
> base-uri($svgDocument)))"/>
> <assert test="empty(index-of($testImages, false()))">The
> image file must exist</assert>
>
> </rule>
> </pattern>
> </schema>
>
> Best regards,
> Alex
>
> On 30-Jul-13 3:33 PM, KAATMAN Matthew wrote:
>
> Hey Alex,
>
> This looks really promising!
>
> When I run validate with this schematron I get the following:
>
> System ID: C:\svn\scripts\svgCheck.sch
>
> Engine name: ISO Schematron (XSLT 2.0)
>
> Severity: fatal
>
> Type: XML validation
>
> Start location: 149:0 (Odd because the schematron is only 14 lines)
>
> System ID: C:\dita\pt\products\vitek2systems\pi\Appendix_A.dita
> (This is the first file with an SVG for the document I checked.)
>
> Engine name: ISO Schematron (XSLT 2.0)
>
> Severity: error
>
> Description: Exception thrown by extension function {public static
> boolean
> com.saxonica.functions.extfn.EXPathFile.exists(java.lang.String)}:
> java.lang.NullPointerException
>
> Type: XML validation
>
> Even if I delete all SVG references, I receive the above two errors.
>
> I then tried it on a map with more SVGs and some that were
> verified to be broken. It is properly detecting the errors but I
> see false positives when the SVG contains embedded images instead
> of linked. I believe it's trying to verify the binary data as the uri.
>
> System ID: C:\dita\en\products\simon\service\Attachments.dita
>
> Engine name: ISO Schematron (XSLT 2.0)
>
> Severity: error
>
> Description: A sequence of more than one item is not allowed as
> the first argument of resolve-uri()
> ("data:image/jpeg;base64,/9j/4AA..."
> <data:image/jpeg;base64,/9j/4AA...>,
> "data:image/png;base64,iVBORw0K..."
> <data:image/png;base64,iVBORw0K...>)
>
> Type: XML validation
>
> Is there a way for me to adjust the schematron to ignore href
> values that start with "data"?
>
> I had previously attended a webinar Oxygen presented on
> schematron. I'm finally starting to understand how powerful it can be!
>
> Thank you,
> Matt
>
> *From:*oxygen-user-bounces at oxygenxml.com
> <mailto:oxygen-user-bounces at oxygenxml.com>
> [mailto:oxygen-user-bounces at oxygenxml.com] *On Behalf Of *Alex Jitianu
> *Sent:* Tuesday, July 30, 2013 2:25 AM
> *To:* oxygen-user at oxygenxml.com <mailto:oxygen-user at oxygenxml.com>
> *Subject:* Re: [oXygen-user] Feature request: Validation for
> linked images in SVG paths
>
> Hello Matt,
>
> In Oxygen v15.0 we've added in the "Validate and check for
> Completeness" dialog a new entry called "Additional schematron
> checks" in which you can specify additional Schematron checks that
> should be be executed on the topics. You can perform the check
> you've described using a Schematron file with the following content:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <schema
> xmlns="http://purl.oclc.org/dsdl/schematron"
> <http://purl.oclc.org/dsdl/schematron>
> queryBinding="xslt2"
> xmlns:exslt="http://expath.org/ns/file"
> <http://expath.org/ns/file>>
> <ns uri="http://expath.org/ns/file"
> <http://expath.org/ns/file> prefix="exslt"/>
> <pattern>
> <rule context="image[ends-with(@href, '.svg')]"
> <mailto:image[ends-with%28 at href,%27.svg%27%29]>>
> <let name="svgDocument" value="document(@href)" />
> <assert
> test="exslt:exists(resolve-uri($svgDocument//*:image/@*:href,
> base-uri($svgDocument)))">
> The image file from the following SVG doesn't
> exist: <value-of select="base-uri($svgDocument)"/></assert>
> </rule>
> </pattern>
> </schema>
>
> Best regards,
> Alex
> --
> Alex Jitianu
> <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
> http://www.oxygenxml.com
>
>
> On 29-Jul-13 9:38 PM, KAATMAN Matthew wrote:
>
> Hey Guys,
>
> This is a feature request that's not extremely crucial, but it
> would be helpful for us.
>
> I'm having our authors create SVG overlays and link to the
> background image (jpeg or png).
>
> Sometimes they accidentally link to an image that isn't in our
> repository path.
>
> Within the SVG, I'll end up with something like:
>
> <image width="1200" height="1807"
> xlink:href="../../../../../../../Users/Username/Pictures/PREVI
> PAV/PAV_printer_cover_open.jpg" >
>
> When it should be:
>
> <image width="1200" height="1807"
> xlink:href="images/PAV_printer_cover_open.jpg" >
>
> Although, the validate/check for completeness wouldn't catch
> this on their workstation as the image exists and is valid, it
> would find it quickly on mine since it's outside the path that
> gets checked in and I'd be missing that image.
>
> It doesn't seem like the OT throws any errors either. The only
> way I find out is when I'm viewing the PDF and notice that
> antenna house has substituted a broken image.
>
> Example:
>
> Thanks!
> Matt
>
> AVIS : Ce courrier et ses pieces jointes sont destines a leur
> seul destinataire et peuvent contenir des informations
> confidentielles appartenant a bioMerieux. Si vous n'etes pas
> destinataire, vous etes informe que toute lecture,
> divulgation, ou reproduction de ce message et des pieces
> jointes est strictement interdite. Si vous avez recu ce
> message par erreur merci d'en prevenir l'expediteur et de le
> detruire, ainsi que ses pieces jointes. NOTICE: This message
> and attachments are intended only for the use of their
> addressee and may contain confidential information belonging
> to bioMerieux. If you are not the intended recipient, you are
> hereby notified that any reading, dissemination, distribution,
> or copying of this message, or any attachment, is strictly
> prohibited. If you have received this message in error, please
> notify the original sender immediately and delete this
> message, along with any attachments.
>
>
>
> _______________________________________________
>
> oXygen-user mailing list
>
> oXygen-user at oxygenxml.com <mailto:oXygen-user at oxygenxml.com>
>
> http://www.oxygenxml.com/mailman/listinfo/oxygen-user
>
> AVIS : Ce courrier et ses pieces jointes sont destines a leur seul
> destinataire et peuvent contenir des informations confidentielles
> appartenant a bioMerieux. Si vous n'etes pas destinataire, vous
> etes informe que toute lecture, divulgation, ou reproduction de ce
> message et des pieces jointes est strictement interdite. Si vous
> avez recu ce message par erreur merci d'en prevenir l'expediteur
> et de le detruire, ainsi que ses pieces jointes. NOTICE: This
> message and attachments are intended only for the use of their
> addressee and may contain confidential information belonging to
> bioMerieux. If you are not the intended recipient, you are hereby
> notified that any reading, dissemination, distribution, or copying
> of this message, or any attachment, is strictly prohibited. If you
> have received this message in error, please notify the original
> sender immediately and delete this message, along with any
> attachments.
>
> AVIS : Ce courrier et ses pieces jointes sont destines a leur seul
> destinataire et peuvent contenir des informations confidentielles
> appartenant a bioMerieux. Si vous n'etes pas destinataire, vous etes
> informe que toute lecture, divulgation, ou reproduction de ce message
> et des pieces jointes est strictement interdite. Si vous avez recu ce
> message par erreur merci d'en prevenir l'expediteur et de le detruire,
> ainsi que ses pieces jointes. NOTICE: This message and attachments are
> intended only for the use of their addressee and may contain
> confidential information belonging to bioMerieux. If you are not the
> intended recipient, you are hereby notified that any reading,
> dissemination, distribution, or copying of this message, or any
> attachment, is strictly prohibited. If you have received this message
> in error, please notify the original sender immediately and delete
> this message, along with any attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.oxygenxml.com/pipermail/oxygen-user/attachments/20130731/4ac4794a/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 8037 bytes
Desc: not available
Url : http://www.oxygenxml.com/pipermail/oxygen-user/attachments/20130731/4ac4794a/attachment-0001.png
More information about the oXygen-user
mailing list