By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

remove blank (xmlns="") from elements

markmcgookin
Expert 100+
P: 648
Hi,

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

Expand|Select|Wrap|Line Numbers
  1. <DateTimeLastSaved xmlns="" />
  2. <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
Dec 10 '07 #1
Share this Question
Share on Google+
4 Replies


jkmyoung
Expert 100+
P: 2,057
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.yahoo.com"
Dec 10 '07 #2

markmcgookin
Expert 100+
P: 648
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)

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="UTF-8" ?>
  3. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.     <xsl:param name="fileName"></xsl:param>
  5.     <xsl:param name="schemaName"></xsl:param>
  6.     <xsl:output method="xml" indent="yes" omit-xml-declaration="no" />
  7.  
  8.     <!-- Template that read the root node -->
  9.     <xsl:template match="/">
  10.  
  11.         <xsl:variable name="myNS">
  12.             <xsl:text>http://tempuri.org/</xsl:text>
  13.             <xsl:value-of select="$schemaName"/>
  14.             <xsl:text>.xsd</xsl:text>
  15.         </xsl:variable>
  16.  
  17.         <xsl:element name="AnswerList" namespace="{$myNS}">
  18.             <!-- NB: Done like this because the template match doesnt work -->
  19.             <!-- May be an issue with the xml that was generated from the QTi -->
  20.             <xsl:element name="DateTimeLastSaved" />
  21.             <xsl:element name="UserName"/>
  22.  
  23.  
  24.             <xsl:for-each select="child::node()">
  25.  
  26.                 <xsl:for-each select="child::node()">
  27.                     <xsl:apply-templates select="DSDetailView/DetailView" />
  28.                     <xsl:for-each select="child::node()">
  29.                         <xsl:apply-templates select="DSDetailView/DetailView" />
  30.                         <xsl:choose>
  31.                             <!-- If it's called Item -->
  32.                             <xsl:when test="name()='Item'">
  33.                                 <xsl:choose>
  34.                                     <!-- If it's a textbox -->
  35.                                     <xsl:when test="@Type='Resco.Controls.DetailView.ItemTextBox'">
  36.                                         <xsl:for-each select="child::node()">
  37.                                             <xsl:choose>
  38.                                                 <!-- If it stored Data i.e. not a lable -->
  39.                                                 <xsl:when test="@Name='DataMember'">
  40.  
  41.                                                     <xsl:variable name="temp">
  42.                                                         <xsl:value-of select="@Value"/>
  43.                                                     </xsl:variable>
  44.  
  45.                                                     <!-- Create a string object in the schema -->
  46.                                                     <xsl:element name="{$temp}">
  47.                                                     </xsl:element>
  48.                                                     <!-- End of create a string object in the schema -->
  49.  
  50.                                                 </xsl:when>
  51.                                             </xsl:choose>
  52.                                         </xsl:for-each>
  53.                                     </xsl:when>
  54.  
  55.                                     <!-- If it's a radio button thing -->
  56.                                     <xsl:when test="@Type='ALPS_Demo.ItemRadioButton, ALPS_Demo'">
  57.                                         <!-- Create an int object in the schema -->
  58.                                         <xsl:for-each select="child::node()">
  59.                                             <xsl:choose>
  60.                                                 <!-- If it stored Data i.e. not a lable -->
  61.                                                 <xsl:when test="@Name='DataMember'">
  62.  
  63.                                                     <xsl:variable name="temp">
  64.                                                         <xsl:value-of select="@Value"/>
  65.                                                     </xsl:variable>
  66.  
  67.                                                     <!-- Create an Int object in the schema -->
  68.                                                     <xsl:element name="{$temp}">
  69.                                                         <xsl:text>-1</xsl:text>
  70.                                                     </xsl:element>
  71.                                                     <!-- Create an Int object in the schema -->
  72.  
  73.                                                 </xsl:when>
  74.                                             </xsl:choose>
  75.                                         </xsl:for-each>
  76.                                     </xsl:when>
  77.                                 </xsl:choose>
  78.                             </xsl:when>
  79.                         </xsl:choose>
  80.                     </xsl:for-each>
  81.                 </xsl:for-each>
  82.             </xsl:for-each>
  83.  
  84.         <!-- Generic Answerlist footer code -->
  85.         </xsl:element>
  86.         <!-- Generic Answerlist footer code -->
  87.  
  88.  
  89.         </xsl:template>
  90. </xsl:stylesheet>
  91.  
  92.  
  93.  
Which I need to produce

Expand|Select|Wrap|Line Numbers
  1. <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd">
  2.     <DateTimeLastSaved />
  3.     <UserName />
  4.     <Ans_1189068258258 />
  5.     <Ans_1188555751625_MC0>-1</Ans_1188555751625_MC0>
  6.     <Ans_1188555751625_MC1>-1</Ans_1188555751625_MC1>
  7.     <Ans_1188555751625_MC2>-1</Ans_1188555751625_MC2>
  8.     <Ans_1188555751625_MC3>-1</Ans_1188555751625_MC3>
  9. </AnswerList>
  10.  
But is producing

Expand|Select|Wrap|Line Numbers
  1. <AnswerList xmlns="http://tempuri.org/ALPS_Assessmentv1p1_RESCO_Schema.xsd">
  2.     <DateTimeLastSaved xmlns="" />
  3.     <UserName xmlns="" />
  4.     <Ans_1189068258258 xmlns="" />
  5.     <Ans_1188555751625_MC0 xmlns="">-1</Ans_1188555751625_MC0>
  6.     <Ans_1188555751625_MC1 xmlns="">-1</Ans_1188555751625_MC1>
  7.     <Ans_1188555751625_MC2 xmlns="">-1</Ans_1188555751625_MC2>
  8.     <Ans_1188555751625_MC3 xmlns="">-1</Ans_1188555751625_MC3>
  9. </AnswerList>
  10.  
Dec 12 '07 #3

jkmyoung
Expert 100+
P: 2,057
Wherever you have an <xsl:element> tag, be sure to use the namespace attribute.
Expand|Select|Wrap|Line Numbers
  1. <xsl:element name="DateTimeLastSaved" namespace="{$myNS}"/>
  2. <xsl:element name="UserName" namespace="{$myNS}"/>
  3.  
Dec 12 '07 #4

P: n/a
awesome.. it worked..
Sep 29 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.