Re: XslTransform is not matching node when source XML contains an xmlns attribute
- From: "David S. Alexander" <david.alexander@xxxxxxxxxxx>
- Date: Mon, 16 Jan 2006 09:38:49 -0800
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/
.
- Follow-Ups:
- Re: XslTransform is not matching node when source XML contains an xmlns attribute
- From: David S. Alexander
- Re: XslTransform is not matching node when source XML contains an xmlns attribute
- References:
- XslTransform is not matching node when source XML contains an xmlns attribute
- From: David S. Alexander
- Re: XslTransform is not matching node when source XML contains an xmlns attribute
- From: David S. Alexander
- Re: XslTransform is not matching node when source XML contains an xmlns attribute
- From: Martin Honnen
- XslTransform is not matching node when source XML contains an xmlns attribute
- Prev by Date: Re: Problems Reading XML File
- Next by Date: Re: XslTransform is not matching node when source XML contains an xmlns attribute
- Previous by thread: Re: XslTransform is not matching node when source XML contains an xmlns attribute
- Next by thread: Re: XslTransform is not matching node when source XML contains an xmlns attribute
- Index(es):
Relevant Pages
|