remove blank (xmlns="") from elements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markmcgookin
    Recognized Expert Contributor
    • Dec 2006
    • 648

    remove blank (xmlns="") from elements

    Hi,

    I am creating an MXL doc using XSLT but for some reason it is churning out elements like this

    Code:
    <DateTimeLastSaved xmlns="" />
    <UserName xmlns="" />
    when I delete xmlns="" it works fine, but if I leave it in there are issues reading/saving the file. Is there any way to remove this xmlns="" in the xslt?

    Cheers,

    Mark
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    When you are creating the elements, you need to have the same namespace as the parent elements (xmlns = XMLNameSpace) . Add the parent's namespace to those elements when you are creating it.

    eg probably something like

    xmlns="www.yaho o.com"

    Comment

    • markmcgookin
      Recognized Expert Contributor
      • Dec 2006
      • 648

      #3
      Hi there,

      I noticed that people were able to solve this problem here, I just hope that re-using this thread will get me a responce here.... I have the same problem, where my xslt is producing elements but all with xmlns="" in them, and when I remove it manually my code works fine, but just using the raw output my code falls over... would anyone be able to help me?

      Thanks very much for any help folks,

      Really appreciated.

      Mark (Code Below)

      Code:
      <?xml version="1.0" encoding="UTF-8" ?>
      <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:param name="fileName"></xsl:param>
          <xsl:param name="schemaName"></xsl:param>
          <xsl:output method="xml" indent="yes" omit-xml-declaration="no" />
      
          <!-- Template that read the root node -->
          <xsl:template match="/">
             
              <xsl:variable name="myNS">
                  <xsl:text>http://tempuri.org/</xsl:text>
                  <xsl:value-of select="$schemaName"/>
                  <xsl:text>.xsd</xsl:text>
              </xsl:variable>
             
              <xsl:element name="AnswerList" namespace="{$myNS}">
                  <!-- NB: Done like this because the template match doesnt work -->
                  <!-- May be an issue with the xml that was generated from the QTi -->
                  <xsl:element name="DateTimeLastSaved" />
                  <xsl:element name="UserName"/>
                 
                 
                  <xsl:for-each select="child::node()">
                     
                      <xsl:for-each select="child::node()">
                          <xsl:apply-templates select="DSDetailView/DetailView" />
                          <xsl:for-each select="child::node()">
                              <xsl:apply-templates select="DSDetailView/DetailView" />
                              <xsl:choose>
                                  <!-- If it's called Item -->
                                  <xsl:when test="name()='Item'">
                                      <xsl:choose>
                                          <!-- If it's a textbox -->
                                          <xsl:when test="@Type='Resco.Controls.DetailView.ItemTextBox'">
                                              <xsl:for-each select="child::node()">
                                                  <xsl:choose>
                                                      <!-- If it stored Data i.e. not a lable -->
                                                      <xsl:when test="@Name='DataMember'">
      
                                                          <xsl:variable name="temp">
                                                              <xsl:value-of select="@Value"/>
                                                          </xsl:variable>
                                                         
                                                          <!-- Create a string object in the schema -->
                                                          <xsl:element name="{$temp}">
                                                          </xsl:element>
                                                          <!-- End of create a string object in the schema -->
      
                                                      </xsl:when>
                                                  </xsl:choose>
                                              </xsl:for-each>
                                          </xsl:when>
      
                                          <!-- If it's a radio button thing -->
                                          <xsl:when test="@Type='ALPS_Demo.ItemRadioButton, ALPS_Demo'">
                                              <!-- Create an int object in the schema -->
                                              <xsl:for-each select="child::node()">
                                                  <xsl:choose>
                                                      <!-- If it stored Data i.e. not a lable -->
                                                      <xsl:when test="@Name='DataMember'">
      
                                                          <xsl:variable name="temp">
                                                              <xsl:value-of select="@Value"/>
                                                          </xsl:variable>
                                                         
                                                          <!-- Create an Int object in the schema -->
                                                          <xsl:element name="{$temp}">
                                                              <xsl:text>-1</xsl:text>
                                                          </xsl:element>
                                                          <!-- Create an Int object in the schema -->
      
                                                      </xsl:when>
                                                  </xsl:choose>
                                              </xsl:for-each>
                                          </xsl:when>
                                      </xsl:choose>
                                  </xsl:when>
                              </xsl:choose>
                          </xsl:for-each>
                      </xsl:for-each>
                  </xsl:for-each>
      
              <!-- Generic Answerlist footer code -->
              </xsl:element>
              <!-- Generic Answerlist footer code -->
      
                         
              </xsl:template>
      </xsl:stylesheet>
      Which I need to produce

      Code:
      <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd">
          <DateTimeLastSaved />
          <UserName />
          <Ans_1189068258258 />
          <Ans_1188555751625_MC0>-1</Ans_1188555751625_MC0>
          <Ans_1188555751625_MC1>-1</Ans_1188555751625_MC1>
          <Ans_1188555751625_MC2>-1</Ans_1188555751625_MC2>
          <Ans_1188555751625_MC3>-1</Ans_1188555751625_MC3>
      </AnswerList>
      But is producing

      Code:
      <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd">
          <DateTimeLastSaved xmlns="" />
          <UserName xmlns="" />
          <Ans_1189068258258 xmlns="" />
          <Ans_1188555751625_MC0 xmlns="">-1</Ans_1188555751625_MC0>
          <Ans_1188555751625_MC1 xmlns="">-1</Ans_1188555751625_MC1>
          <Ans_1188555751625_MC2 xmlns="">-1</Ans_1188555751625_MC2>
          <Ans_1188555751625_MC3 xmlns="">-1</Ans_1188555751625_MC3>
      </AnswerList>

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        Wherever you have an <xsl:element> tag, be sure to use the namespace attribute.
        Code:
        <xsl:element name="DateTimeLastSaved" namespace="{$myNS}"/>
        <xsl:element name="UserName" namespace="{$myNS}"/>

        Comment

        • vignesh hari

          #5
          awesome.. it worked..

          Comment

          Working...