Re: XslTransform is not matching node when source XML contains an xmlns attribute

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Martin,

Thanks a lot for taking the time to help me out. I appreciate it. Now I can
hopefully get my proof of concept proven, conceptually, anyway.

Regards,

David S. Alexander

"Martin Honnen" <mahotrash@xxxxxxxx> wrote in message
news:%23Mhl6nQGGHA.3984@xxxxxxxxxxxxxxxxxxxxxxx
>
>
> David S. Alexander wrote:
>
>> I made progress. I figured out what was causing my transform to return
>> nothing, but I don't understand why it caused a problem. The problem was
>> in my XSLT. Can someone explain default namespaces in XSLTs?
>
> default namespaces is nothing defined for XSLT itself, it is something
> defined for XML.
> Of course you have use default namespaces in XSLT as XSLT is XML so you
> could e.g. do
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> xmlns="http://www.w3.org/1999/xhtml";
> version="1.0">
>
> <xsl:template match="/">
> <html xml:lang="en">
> and so on to ensure that your literal result elements (like that html
> element) are in the namespace with namespace URI
> http://www.w3.org/1999/xhtml.
> The XPath 1.0 language that is used in XSLT 1.0 to XPath expressions and
> for match patterns does not have any concept of a default namespace which
> means to match an element in a particular namespace you need to write an
> XPath expression with a qualified name consisting of a prefix and a local
> name e.g.
> pf:element-name
> where the prefix pf must be bound the the namespace URI of the elements
> you want to select.
> See
> <http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>
> for more explanation.
>
>
> > I am still getting the
>> leading "o;?" and a bunch of trailing '\0' characters, which I don't
>> understand.
>
>
>>>MemoryStream transformedXmlStream = new MemoryStream();
>>>
>>>// Transform the file
>>>xslTransform.Transform(xPathDocument, null, transformedXmlStream, null);
>>>
>>>// Convert output MemoryStream to a string
>>>ASCIIEncoding ascii = new ASCIIEncoding();
>>>string outputXmlString =
>>>ascii.GetString(transformedXmlStream.GetBuffer());
>
> If you try to decode a byte stream like a memory stream to a string then
> of course it matters that you choose the proper encoding for decoding,
> otherwise the decoding will produce characters that were not in the byte
> stream. The output stream was probably UTF-16 or UTF-8 encoded and not
> ASCII encoded.
>
> There is no need however to use a memory stream and later convert to a
> string yourself if all you want is a string, you can directly transform to
> a StringWriter
> <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemIOStringWriterClassTopic.asp>
> <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXslXslTransformClassTransformTopic14.asp>
> e.g. pseudo code
> StringWriter stringResult = new StringWriter();
> xslTransform.Transform(xPathDocument, null, stringResult, null);
> string result = stringResult.ToString();
> stringResult.Close()
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/


.



Relevant Pages

  • Re: XslTransform is not matching node when source XML contains an xmlns attribute
    ... characters went away and using StringWriter got rid of all the trailing '\0' ... >>> in my XSLT. ... >> element) are in the namespace with namespace URI ... >> If you try to decode a byte stream like a memory stream to a string then ...
    (microsoft.public.dotnet.xml)
  • Re: XslTransform is not matching node when source XML contains an xmlns attribute
    ... The problem was in my XSLT. ... Of course you have use default namespaces in XSLT as XSLT is XML so you could e.g. do ... and so on to ensure that your literal result elements are in the namespace with namespace URI http://www.w3.org/1999/xhtml. ... There is no need however to use a memory stream and later convert to a string yourself if all you want is a string, you can directly transform to a StringWriter ...
    (microsoft.public.dotnet.xml)
  • Re: Question about design, defmacro, macrolet, and &environment
    ... "Expects to find the literal string on the stream." ... (defun send (string &optional stream) ... (declaim (inline make-adjustable-string)) ...
    (comp.lang.lisp)
  • Re: Strange problem when not in debugger
    ... private string huidigWeb; ... int buffLength = 2048; ... // Opens a file stream to read the file to be uploaded ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ReplacerStream
    ... string, do a replace on that string and create a stream again to be ... If those are problems, and you are looking just for a single string, it seems to me that you could just read the stream one character at a time, checking to see if it matches the current character in your search string. ...
    (microsoft.public.dotnet.framework)