xmlxslt

xslt data is repeating


I am trying to understand why my data is repeating Clinical Content in the output. In the xslt I have a for-each select="//EmailMessageModel so it shouldnt repeat that data because it is in only one of the EmailMessageModel

data

<?xml version="1.0" encoding="utf-16"?>
<ArrayOfEmailMessageModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <EmailMessageModel>
        
        </EmailContentModel>
    </EmailMessageModel>
</ArrayOfEmailMessageModel>

xslt

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
      <xsl:output method="xml" indent="yes"/>
  <xsl:template match="//ArrayOfEmailMessageModel">
    <xsl:variable name="showGlobalHeader" select="true()"/>
    <xsl:for-each select="//EmailMessageModel">
        <h4>
            <xsl:value-of select=".//Header" disable-output-escaping="yes"/>
        </h4>
        <xsl:for-each select="//EmailContentModel/EmailContentModel">
            
            </xsl:choose>
        </xsl:for-each>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

output

<?xml version="1.0" encoding="utf-16"?>
<h4>Adolescent and Young Adult (AYA) Oncology Version 1.2026</h4>

<ul>

Solution

  • Well, you're overusing the leading // as you're using it twice in two nested for-each, that way for each and all of the elements the outer for-each selects in the entire document the inner for-each processes all elements it selects in the entire document. Use precise paths or at least relative ones starting with e.g. .//