 |
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
|
|
|

September 13th, 2007, 12:19 PM
|
Registered User
|
|
Join Date: Sep 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

September 13th, 2007, 12:26 PM
|
 |
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
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|

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.
|

September 14th, 2007, 05:46 AM
|
 |
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 -/
|

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.
|
|
 |