Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   how can I do this ? (http://www.velocityreviews.com/forums/t166365-how-can-i-do-this.html)

Julio 01-07-2004 01:34 PM

how can I do this ?
 
Hi, I have problem with namespaces and attributes.
I want to get this:

<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"
>


I have the following XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

<xsl:template match="/">
<xsl:element name="grammar">
<xsl:attribute name="xmlns">http://www.w3.org/2001/06/grammar</xsl:attribute>
<xsl:attribute name="sapi"
namespace="xmlns">http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions</xsl:attribute>
</xsl:element>
</xsl:template>


but I can't get what I want, it don't work. Can anyone help me out?
Thanks in advance.
Julio

Pieter Vandepitte 01-07-2004 02:46 PM

Re: how can I do this ?
 
Strange, it _does_ work for me... but i appended
</xsl:stylesheet>
to your stylesheet :)

w.kind regards
Pitter

Julio wrote:
> Hi, I have problem with namespaces and attributes.
> I want to get this:
>
> <grammar xmlns="http://www.w3.org/2001/06/grammar"
> xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"
>
>
> I have the following XSLT:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
>
> <xsl:template match="/">
> <xsl:element name="grammar">
> <xsl:attribute name="xmlns">http://www.w3.org/2001/06/grammar</xsl:attribute>
> <xsl:attribute name="sapi"
> namespace="xmlns">http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions</xsl:attribute>
> </xsl:element>
> </xsl:template>
>
>
> but I can't get what I want, it don't work. Can anyone help me out?
> Thanks in advance.
> Julio



Patrick TJ McPhee 01-07-2004 06:39 PM

Re: how can I do this ?
 
In article <8b7fc91b.0401070534.1661ebe7@posting.google.com >,
Julio <jkriger@hotpop.com> wrote:

% I want to get this:
%
% <grammar xmlns="http://www.w3.org/2001/06/grammar"
% xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"
% >

% I have the following XSLT:
%
% <?xml version="1.0" encoding="UTF-8"?>
% <xsl:stylesheet version="1.0"
% xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
% <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
%
% <xsl:template match="/">
% <xsl:element name="grammar">
% <xsl:attribute
% name="xmlns">http://www.w3.org/2001/06/grammar</xsl:attribute>

Don't treat the name space declaration as an ordinary attribute. Just
declare the name space, and it should be emitted as needed. For instance,
if you put

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/2001/06/grammar"
xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions">

at the top of your style sheet, you can put

<grammar>
<sapi:excuse-my-ignorance/>
</grammar>

In your template, and it will come out with the appropriate name space
declarations.

--

Patrick TJ McPhee
East York Canada
ptjm@interlog.com

Julio Kriger 01-08-2004 01:09 PM

Re: how can I do this ?
 
Hi, I'm using XmlSpy 2004 and I don't what I want.
Which xslt engine are you using?
Cheers!



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Julio Kriger 01-08-2004 01:19 PM

Re: how can I do this ?
 
Hi, I supose if I try what you say it will work. However, I only need
the attribute
'xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"
' to say to the grammar compiler to use some extension to build the
binary file of the grammar.
Let me show what I need to get, you will see that I don't need a tag
<sapi:whatever ... />.

<grammar xmlns="http://www.w3.org/2001/06/grammar"
xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"
xml:lang="en-US" tag-format="semantics-ms/1.0" version="1.0"
mode="voice">
<rule id="root" scope="public">
<tag>$.Result={}</tag>
<one-of>
<item>
<item>Boston Fortune</item>
<tag>$.Result.FirstName=Boston</tag>
<tag>$.Result.LastName=Fortune</tag>
<tag>$.Result.Extension=123</tag>
<tag>$.Result.Department=Development</tag>
</item>
<item>
<item>Londo Deamon</item>
<tag>$.Result.FirstName=Londo</tag>
<tag>$.Result.LastName=Deamon</tag>
<tag>$.Result.Extension=456</tag>
<tag>$.Result.Department=Development</tag>
</item>
<item>
<item>Oxford Cowboy</item>
<tag>$.Result.FirstName=Oxford</tag>
<tag>$.Result.LastName=Cowboy</tag>
<tag>$.Result.Extension=789</tag>
<tag>$.Result.Department=Research</tag>
</item>
</one-of>
</rule>
</grammar>


Now I have it working with the following xslt, but I beleive it's a
workaround and not a good solution:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"
xmlns="http://www.w3.org/2001/06/grammar">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

<xsl:template match="/">
<grammar
xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"
xml:lang="en-US" tag-format="semantics-ms/1.0" version="1.0"
mode="voice" xmlns="http://www.w3.org/2001/06/grammar">
<!--
<xsl:element name="grammar">
<xsl:attribute
name="xmlns">http://www.w3.org/2001/06/grammar</xsl:attribute>
<xsl:attribute
name="xmlns:sapi">http://schemas.microsoft.com/Speech/2002/06/SRGSExtens
ions</xsl:attribute>

<xsl:attribute name="xml:lang">en-US</xsl:attribute>
<xsl:attribute name="tag-format">semantics-ms/1.0</xsl:attribute>
<xsl:attribute name="version">1.0</xsl:attribute>
<xsl:attribute name="mode">voice</xsl:attribute>
-->
<xsl:element name="rule">
<xsl:attribute name="id">root</xsl:attribute>
<xsl:attribute name="scope">public</xsl:attribute>

<xsl:call-template name="tag">
<xsl:with-param name="name">$.Result</xsl:with-param>
<xsl:with-param name="value">{}</xsl:with-param>
</xsl:call-template>

<xsl:element name="one-of">
<xsl:for-each select="//User">
<xsl:call-template name="user" />
</xsl:for-each>
</xsl:element>
</xsl:element>
<!--
</xsl:element>
-->
</grammar>
</xsl:template>

<xsl:template name="tag">
<xsl:param name="name" />
<xsl:param name="value" />

<xsl:element name="tag">
<xsl:value-of select="$name" />
<xsl:text>=</xsl:text>
<xsl:value-of select="$value" />
</xsl:element>
</xsl:template>

<xsl:template name="user">
<xsl:element name="item">
<xsl:element name="item">
<xsl:value-of select="./FirstName" />
<xsl:text> </xsl:text>
<xsl:value-of select="./LastName" />
</xsl:element>

<xsl:call-template name="tag">
<xsl:with-param name="name">$.Result.FirstName</xsl:with-param>
<xsl:with-param name="value"><xsl:value-of select="./FirstName"
/></xsl:with-param>
</xsl:call-template>

<xsl:call-template name="tag">
<xsl:with-param name="name">$.Result.LastName</xsl:with-param>
<xsl:with-param name="value"><xsl:value-of select="./LastName"
/></xsl:with-param>
</xsl:call-template>

<xsl:call-template name="tag">
<xsl:with-param name="name">$.Result.Extension</xsl:with-param>
<xsl:with-param name="value"><xsl:value-of select="./Extension"
/></xsl:with-param>
</xsl:call-template>

<xsl:call-template name="tag">
<xsl:with-param name="name">$.Result.Department</xsl:with-param>
<xsl:with-param name="value"><xsl:value-of select="./Department"
/></xsl:with-param>
</xsl:call-template>
</xsl:element>
</xsl:template>

</xsl:stylesheet>

As you can see, there are some part that are commented becuase they
don't work.

Cheers!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Patrick TJ McPhee 01-08-2004 04:56 PM

Re: how can I do this ?
 
In article <3ffd58df$0$70305$75868355@news.frii.net>,
Julio Kriger <jkriger@hotpop.com> wrote:

% Hi, I supose if I try what you say it will work. However, I only need
% the attribute
% 'xmlns:sapi="http://schemas.microsoft.com/Speech/2002/06/SRGSExtensions"
% ' to say to the grammar compiler to use some extension to build the
% binary file of the grammar.

This sounds like a misuse of the name space declaration.

% Now I have it working with the following xslt, but I beleive it's a
% workaround and not a good solution:

I'm not sure what your problem is. Do you mean you would rather have
<xsl:element name='grammar'>
...

rather than
<grammar ...>

?

Blech. In my opinion, you should never use xsl:element or xsl:attribute
unless you need to generate the names dynamically. It makes the
stylesheet about a hundred times harder to read when you do.

If it's not that, then what's the problem?
--

Patrick TJ McPhee
East York Canada
ptjm@interlog.com

Julio Kriger 01-08-2004 06:09 PM

Re: how can I do this ?
 
Hi,
I would rather user <xsl:element name='grammar'> than <grammar ...>
I beleive it's more properly done this way (<xsl:element
name='grammar'>) than the other way (<grammar ...>).
Maybe it's a really misuse of namespace declaration. I don't know.
I have created a C# program that create this kind of grammar files, with
the use of createelement and createattibute of the xmldocument object. I
thouht it will be same with XSLT.
Cheers!


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Patrick TJ McPhee 01-09-2004 06:14 PM

Re: how can I do this ?
 
In article <3ffd9cda$0$70302$75868355@news.frii.net>,
Julio Kriger <jkriger@hotpop.com> wrote:

% I would rather user <xsl:element name='grammar'> than <grammar ...>
% I beleive it's more properly done this way (<xsl:element
% name='grammar'>) than the other way (<grammar ...>).

Just get that idea out of your head. I mean, do it if you want, but
don't imagine it's more proper. To me, it's harder to read, harder
to maintain and just generally worse in every way imaginable.

Having said that, if you control the semantics behind this use of
xmlns:whatever, then change the way you do things. Create an attribute
in your own name space which tells your code to do whatever it is
you need to do, rather than depending on a particular name space
declaration being present.
--

Patrick TJ McPhee
East York Canada
ptjm@interlog.com


All times are GMT. The time now is 04:43 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.