Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old September 13th, 2007, 12:19 PM
Registered User
Join Date: Sep 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default base 64 data in transform

A couple of questions:

1) I've been looking around for a way to do this with no luck.

I'm getting the path to a base-64 file (happens to be a .tif) as a parameter in my transform.

I'd like to create a node containing the binary content of that file.

2) I think this is pretty close; I identify the node I want to change by finding a sibling which has the magic code, and using preceding-sibling. (Pretend "bob" is the eventual binary stream):

    <xsl:template match="//ns:AttachmentType[@tc='57']">
        <xsl:if test="preceding-sibling::ns:AttachmentData">
            <xsl:element name="ns:AttachmentData">
        <xsl:element name="ns:AttachmentType">
            <xsl:attribute name="tc">1003801006</xsl:attribute>

But I really want to replace the data in the related AttachmentData node, not create a new one. How far off am I?

Thank you very much.

Old September 13th, 2007, 12:26 PM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

Do your two questions have anything to do with each other? I'm confused.

1. XML can't store binary data. Best to keep it in base 64. You can read the file as text using unparsed-text() in XSLT 2.0. In 1.0 you would need an extension function.

2. XSLT can't modify existing nodes. It always transforms an input document to create an output document.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Old September 13th, 2007, 01:05 PM
Registered User
Join Date: Sep 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks very much for the reply.

They're only related in that #1 is asking how to transform the content of an existing AttachmentData node from a file on disk, and #2 is asking the right way to locate that node from its sibling.

Maybe I'm using the wrong terminology, but yes, what I want to do is take the stream of a base 64 file and create an element in an XML document I'm transforming.

I see your point, I'm not really modifying a node, what I want to do is locate a node in an existing document, change that node's value, and create an entirely new document.

Somehow I need to make the node found by the preceding-sibling the active node, and get the base 64 data in it. I'll have to work on that and look into the extension or trying xslt 2.0.

Thanks again, your book is an invaluable reference.

Old September 14th, 2007, 05:46 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

To find the first preceding sibling you simply need to do this:

<xsl:if test="preceding-sibling::ns:AttachmentData[1]">

In answer to the other part of your question, as Michael says, there is no way in XSLT to load a binary or text file, unless it is an XML file (I don't believe that the file format for .TIF is XML is it).

/- Sam Judson : Wrox Technical Editor -/
Old September 14th, 2007, 08:39 AM
Registered User
Join Date: Sep 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks. For the sibling thing, I finally realized that I needed a template for the AttachmentData (which I wanted to alter), then test for the following-sibling of AttachmentType, works out.

For the .tif thing, you're right, tif is not an xml-based file, it's an image format. Took a while, but I got the extension processing figured out (at least MSFT's version thereof, which is the environment with which I must deal).

Thanks again for the assistance, I appreciate it.

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to protect data base Rajesh Pachouri Pro VB 6 1 September 23rd, 2006 03:33 AM
64 Bit - Issue in 64 bit IIS calling Win32 API Hubman General .NET 1 August 24th, 2006 09:19 AM
Transfering data from csv file to data base g_vamsi_krish ASP.NET 1.0 and 1.1 Professional 2 May 16th, 2006 11:58 PM
Transform data does not change Vince.Stanzione XSLT 0 September 22nd, 2005 12:01 PM
Data Base Connection ashraf Javascript 4 November 27th, 2004 06:56 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.