how can I do this ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Julio

    #1

    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="htt p://schemas.microso ft.com/Speech/2002/06/SRGSExtensions"[color=blue]
    >[/color]

    I have the following XSLT:

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

    <xsl:template match="/">
    <xsl:element name="grammar">
    <xsl:attribut e name="xmlns">ht tp://www.w3.org/2001/06/grammar</xsl:attribute>
    <xsl:attribut e name="sapi"
    namespace="xmln s">http://schemas.microso ft.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

    #2
    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:[color=blue]
    > Hi, I have problem with namespaces and attributes.
    > I want to get this:
    >
    > <grammar xmlns="http://www.w3.org/2001/06/grammar"
    > xmlns:sapi="htt p://schemas.microso ft.com/Speech/2002/06/SRGSExtensions"
    >
    >
    > I have the following XSLT:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsl:styleshe et version="1.0"
    > xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
    > <xsl:output method="xml" indent="yes" omit-xml-declaration="ye s" />
    >
    > <xsl:template match="/">
    > <xsl:element name="grammar">
    > <xsl:attribut e name="xmlns">ht tp://www.w3.org/2001/06/grammar</xsl:attribute>
    > <xsl:attribut e name="sapi"
    > namespace="xmln s">http://schemas.microso ft.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[/color]

    Comment

    • Patrick TJ McPhee

      #3
      Re: how can I do this ?

      In article <8b7fc91b.04010 70534.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="htt p://schemas.microso ft.com/Speech/2002/06/SRGSExtensions"
      % >

      % I have the following XSLT:
      %
      % <?xml version="1.0" encoding="UTF-8"?>
      % <xsl:styleshe et version="1.0"
      % xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
      % <xsl:output method="xml" indent="yes" omit-xml-declaration="ye s" />
      %
      % <xsl:template match="/">
      % <xsl:element name="grammar">
      % <xsl:attribut e
      % name="xmlns">ht tp://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:styleshe et version="1.0"
      xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
      xmlns="http://www.w3.org/2001/06/grammar"
      xmlns:sapi="htt p://schemas.microso ft.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.c om

      Comment

      • Julio Kriger

        #4
        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!

        Comment

        • Julio Kriger

          #5
          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="ht tp://schemas.microso ft.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:whateve r ... />.

          <grammar xmlns="http://www.w3.org/2001/06/grammar"
          xmlns:sapi="htt p://schemas.microso ft.com/Speech/2002/06/SRGSExtensions"
          xml:lang="en-US" tag-format="semanti cs-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.F irstName=Boston </tag>
          <tag>$.Result.L astName=Fortune </tag>
          <tag>$.Result.E xtension=123</tag>
          <tag>$.Result.D epartment=Devel opment</tag>
          </item>
          <item>
          <item>Londo Deamon</item>
          <tag>$.Result.F irstName=Londo</tag>
          <tag>$.Result.L astName=Deamon</tag>
          <tag>$.Result.E xtension=456</tag>
          <tag>$.Result.D epartment=Devel opment</tag>
          </item>
          <item>
          <item>Oxford Cowboy</item>
          <tag>$.Result.F irstName=Oxford </tag>
          <tag>$.Result.L astName=Cowboy</tag>
          <tag>$.Result.E xtension=789</tag>
          <tag>$.Result.D epartment=Resea rch</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:styleshe et version="1.0"
          xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
          xmlns:sapi="htt p://schemas.microso ft.com/Speech/2002/06/SRGSExtensions"
          xmlns="http://www.w3.org/2001/06/grammar">
          <xsl:output method="xml" indent="yes" omit-xml-declaration="ye s" />

          <xsl:template match="/">
          <grammar
          xmlns:sapi="htt p://schemas.microso ft.com/Speech/2002/06/SRGSExtensions"
          xml:lang="en-US" tag-format="semanti cs-ms/1.0" version="1.0"
          mode="voice" xmlns="http://www.w3.org/2001/06/grammar">
          <!--
          <xsl:element name="grammar">
          <xsl:attribut e
          name="xmlns">ht tp://www.w3.org/2001/06/grammar</xsl:attribute>
          <xsl:attribut e
          name="xmlns:sap i">http://schemas.microsoft.com/Speech/2002/06/SRGSExtens
          ions</xsl:attribute>

          <xsl:attribut e name="xml:lang" >en-US</xsl:attribute>
          <xsl:attribut e name="tag-format">semanti cs-ms/1.0</xsl:attribute>
          <xsl:attribut e name="version"> 1.0</xsl:attribute>
          <xsl:attribut e name="mode">voi ce</xsl:attribute>
          -->
          <xsl:element name="rule">
          <xsl:attribut e name="id">root</xsl:attribute>
          <xsl:attribut e name="scope">pu blic</xsl:attribute>

          <xsl:call-template name="tag">
          <xsl:with-param name="name">$.R esult</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">$.R esult.FirstName </xsl:with-param>
          <xsl:with-param name="value"><x sl:value-of select="./FirstName"
          /></xsl:with-param>
          </xsl:call-template>

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

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

          <xsl:call-template name="tag">
          <xsl:with-param name="name">$.R esult.Departmen t</xsl:with-param>
          <xsl:with-param name="value"><x sl: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!

          Comment

          • Patrick TJ McPhee

            #6
            Re: how can I do this ?

            In article <3ffd58df$0$703 05$75868355@new s.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="ht tp://schemas.microso ft.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.c om

            Comment

            • Julio Kriger

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

              Comment

              • Patrick TJ McPhee

                #8
                Re: how can I do this ?

                In article <3ffd9cda$0$703 02$75868355@new s.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.c om

                Comment

                Working...