Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 13th, 2007, 12:19 PM
Registered User
 
Join Date: Sep 2007
Location: Boulder, CO, USA.
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">
                bob
            </xsl:element>
        </xsl:if>
        <xsl:element name="ns:AttachmentType">
            <xsl:attribute name="tc">1003801006</xsl:attribute>
            <xsl:text>APS</xsl:text>
        </xsl:element>
    </xsl:template>

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.

Reply With Quote
  #2 (permalink)  
Old September 13th, 2007, 12:26 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old September 13th, 2007, 01:05 PM
Registered User
 
Join Date: Sep 2007
Location: Boulder, CO, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #4 (permalink)  
Old September 14th, 2007, 05:46 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

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 -/
Reply With Quote
  #5 (permalink)  
Old September 14th, 2007, 08:39 AM
Registered User
 
Join Date: Sep 2007
Location: Boulder, CO, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:18 PM.


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