CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: XSLT question

  1. #1
    Join Date
    Jan 2023
    Posts
    2

    XSLT question

    Hi,

    I'm quite new to xslt and I'm trying to understand the inner for-loop in the code below. I think
    it loops over all <ClassifiedProductDefinition> elements with a <SpeciesGroupKey> that matches the
    the one in <SpeciesGroupDefinition> and where none of the preceding <ClassifiedProductDefinition>
    elements have the same <SpeciesGroupKey> and <ProductGroupName> as the current <ClassifiedProductDefinition>
    element. Is this correct or am I missing something here?

    Code:
    <xsl:variable name="productGroups">
       <xsl:for-each select="hpr:SpeciesGroupDefinition">
         <xsl:variable name="species" select="hpr:SpeciesGroupKey"/>
    	<xsl:for-each select="../hpr:ProductDefinition/hpr:ClassifiedProductDefinition[hpr:SpeciesGroupKey = $species and not(./hpr:ProductGroupName = preceding::[hpr:SpeciesGroupKey = $species]/hpr:ProductGroupName)]">
    	  <Product>
    	    <xsl:copy-of select="hpr:SpeciesGroupKey"/>
    	    <xsl:copy-of select="hpr:ProductGroupName"/>
    	  </Product>
           </xsl:for-each>
        </xsl:for-each>
    </xsl:variable>

  2. #2
    Join Date
    Nov 2018
    Posts
    120

    Re: XSLT question

    My first suggestion would be for you to generate a minimal XML document containing a couple of elements
    - one which passes the tests (as you understand it)
    - one which fails the tests

    Or take an existing document and make a copy of it, containing just a few representative elements.

    Does applying your xslt to that document produce the result you want?

  3. #3
    Join Date
    Jan 2023
    Posts
    2

    Re: XSLT question

    Thanks for the suggestion, Salem. What I'm not sure of is if the condition [hpr:SpeciesGroupKey = $species]
    is negated or if it selects all elements with same <SpeciesGroupKey> and different <ProductGroupName>.
    I didn't write the xslt code. I'm just trying to understand what it does.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured