how can I do this ?

Discussion in 'XML' started by Julio, Jan 7, 2004.

  1. Julio

    Julio Guest

    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:eek:utput 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
    Julio, Jan 7, 2004
    #1
    1. Advertising

  2. 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:eek:utput 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, Jan 7, 2004
    #2
    1. Advertising

  3. In article <>,
    Julio <> 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:eek:utput 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
    Patrick TJ McPhee, Jan 7, 2004
    #3
  4. Julio

    Julio Kriger Guest

    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, Jan 8, 2004
    #4
  5. Julio

    Julio Kriger Guest

    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:eek:utput 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!
    Julio Kriger, Jan 8, 2004
    #5
  6. In article <3ffd58df$0$70305$>,
    Julio Kriger <> 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
    Patrick TJ McPhee, Jan 8, 2004
    #6
  7. Julio

    Julio Kriger Guest

    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!
    Julio Kriger, Jan 8, 2004
    #7
  8. In article <3ffd9cda$0$70302$>,
    Julio Kriger <> 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
    Patrick TJ McPhee, Jan 9, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob
    Replies:
    1
    Views:
    384
    Shawn B.
    Jan 12, 2004
  2. Richard Dixson
    Replies:
    1
    Views:
    509
    Joe Fallon
    May 18, 2004
  3. Rutger Smit
    Replies:
    1
    Views:
    543
    =?Utf-8?B?THVrZWI=?=
    Sep 6, 2004
  4. duncan
    Replies:
    2
    Views:
    6,082
  5. Casey Hawthorne
    Replies:
    1
    Views:
    713
    Arne Vajhøj
    Mar 18, 2009
Loading...

Share This Page