title: How do I add prefix for elements' attributes using XSLT?
body: <p>I am stuck on how to add prefix <strong>ext:</strong> for my attributes. I would like to add ext to approximateDateIndicator, currentIndicator, DateOfBirthIndicator so they look like this:
  <strong>ext:approximateDateIndicator **ext:currentIndicator</strong> <strong>ext:DateOfBirthIndicator</strong></p>
  
  <p>My xslt has a namespace <strong>xmlns:ext="http://www.courts.state.dc.us/ProtectionOrderExtension/1.0"</strong>. </p>
  
  <p><strong>My output is not adding the ext:</strong></p>
  
  <pre><code>&lt;ext:PersonBirthDate&gt;
      &lt;ext:PersonBirthDate approximateDateIndicator="false" currentIndicator="false" DateOfBirthIndicator="true"&gt;1988-09-01&lt;/ext:PersonBirthDate&gt;
      &lt;ext:PersonBirthDate approximateDateIndicator="false" currentIndicator="false" DateOfBirthIndicator="true"&gt;1988-09-02&lt;/ext:PersonBirthDate&gt;
      &lt;ext:PersonBirthDate approximateDateIndicator="false" currentIndicator="true" DateOfBirthIndicator="true"&gt;1990-01-01&lt;/ext:PersonBirthDate&gt;
      &lt;/ext:PersonBirthDate&gt;
  </code></pre>
  
  <p><strong>My xslt code</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ext="http://www.courts.state.Dc.us/ProtectionOrderExtension/1.0"&gt;
      &lt;xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/&gt;
      &lt;xsl:template name="ProtectionOrder"&gt;
          &lt;ext:ProtectionOrder&gt;
              &lt;xsl:variable name="vProtectionOrderID"&gt;
                  &lt;xsl:value-of select="@InternalProtectionOrderID"/&gt;
              &lt;/xsl:variable&gt;
      &lt;!--Respondent --&gt;
              &lt;xsl:for-each select="RespondentPartyID"&gt;
                  &lt;xsl:for-each select="//CaseParty[(@InternalPartyID=current()/@InternalPartyID) and (Connection[(@Word='RSP') ])]"&gt;
                      &lt;xsl:for-each select="//Party[@InternalPartyID=current()/@InternalPartyID]"&gt;
                          &lt;xsl:call-template name="Respondent"&gt;
                              &lt;xsl:with-param name="pProtectionOrderID"&gt;
                                  &lt;xsl:value-of select="$vProtectionOrderID"/&gt;
                              &lt;/xsl:with-param&gt;
                          &lt;/xsl:call-template&gt;
                      &lt;/xsl:for-each&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/xsl:for-each&gt;
          &lt;/ext:ProtectionOrder&gt;
      &lt;/xsl:template&gt;
  
      &lt;!--Template for DateOfBirth for the respondent--&gt;
      &lt;xsl:template match="DateOfBirth"&gt;
          &lt;ext:PersonBirthDate&gt;
              &lt;xsl:attribute name="approximateDateIndicator"&gt;false&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="currentIndicator"&gt;false&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="DateOfBirthIndicator"&gt;true&lt;/xsl:attribute&gt;
              &lt;xsl:value-of select="mscef:formatDate(string(.))"/&gt;
          &lt;/ext:PersonBirthDate&gt;
      &lt;/xsl:template&gt;
      &lt;!--Template for DateOfBirth or the respondent where Current = true --&gt;
      &lt;xsl:template match="DateOfBirth[@Current='true']"&gt;
          &lt;ext:PersonBirthDate&gt;
              &lt;xsl:attribute name="approximateDateIndicator"&gt;false&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="currentIndicator"&gt;true&lt;/xsl:attribute&gt;
              &lt;xsl:attribute name="DateOfBirthIndicator"&gt;true&lt;/xsl:attribute&gt;
              &lt;xsl:value-of select="mscef:formatDate(string(.))"/&gt;
          &lt;/ext:PersonBirthDate&gt;
      &lt;/xsl:template&gt;
      &lt;!--Template for ApproximateDOB for the respondent--&gt;
      &lt;xsl:template match="ApproximateDOB"&gt;
          &lt;ext:PersonBirthDate ext:approximateDateIndicator="true" ext:currentIndicator="{not(../DateOfBirth)}" ext:DateOfBirthIndicator="false"&gt;
              &lt;xsl:value-of select="mscef:formatDate(string(.))"/&gt;
          &lt;/ext:PersonBirthDate&gt;
      &lt;/xsl:template&gt;
      &lt;!--Respondent Template--&gt;
      &lt;xsl:template name="Respondent"&gt;
          &lt;xsl:param name="pProtectionOrderID"/&gt;
          &lt;ext:Respondent&gt;
              &lt;ext:PersonRaceCode&gt;
                  &lt;xsl:value-of select="//CaseParty[@ID=current()/@ID]/ObservedRace/@Word"/&gt;
              &lt;/ext:PersonRaceCode&gt;
      &lt;!--Guardian --&gt;
              &lt;xsl:for-each select="//CaseParty[(Connection[(@Word='GRD')])][1]"&gt;
                  &lt;xsl:for-each select="//Party[@InternalPartyID=current()/@InternalPartyID]"&gt;
                      &lt;xsl:call-template name="Guardian"/&gt;
                  &lt;/xsl:for-each&gt;
              &lt;/xsl:for-each&gt;
      &lt;!-- This is the date of birth of the respondent which is based on the 3 templates above (ApproximateDOB, DateOfBirth[@Current='true'] and DateOfBirth  --&gt;
              &lt;ext:PersonBirthDate&gt;
                  &lt;xsl:apply-templates select="ApproximateDOB|DateOfBirth"/&gt;
              &lt;/ext:PersonBirthDate&gt;
          &lt;/ext:Respondent&gt;
      &lt;/xsl:template&gt;
      &lt;!--Guardian Template--&gt;
      &lt;xsl:template name="Guardian"&gt;
          &lt;ext:Guardian&gt;
              &lt;xsl:for-each select="Race"&gt;
                  &lt;ext:PersonRaceCode&gt;
                      &lt;xsl:value-of select="@Word"/&gt;
                  &lt;/ext:PersonRaceCode&gt;
              &lt;/xsl:for-each&gt;
          &lt;/ext:Guardian&gt;
      &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p><strong>My xml code</strong></p>
  
  <pre><code>&lt;Party ID="76"&gt;
          &lt;Gender Word="F "&gt;Female&lt;/Gender&gt;
          &lt;NotifyElectronically&gt;0&lt;/NotifyElectronically&gt;
          &lt;NeedsInterpreter&gt;false&lt;/NeedsInterpreter&gt;
          &lt;PartyInJailFlag&gt;false&lt;/PartyInJailFlag&gt;
          &lt;ApproximateDOB&gt;3/4/1956&lt;/ApproximateDOB&gt;
          &lt;DateOfBirth&gt;04/21/1956&lt;/DateOfBirth&gt;
          &lt;DateOfBirth Current="true"&gt;05/21/1956&lt;/DateOfBirth&gt;
  &lt;/Party&gt;
  </code></pre>