My question is similar to this one, in which the author asks how to find the minimum attribute of an set of elements. I'm a beginner at xpath and I'm having trouble taking that answer and adding it to my XSLT. I need to find the minimum price of a Plan (see below) and add an attribute to the Subdivision containing that minimum.
I have the following XML snippet:
<Subdivision Status="Active">
<SubdivisionName>Chesla</SubdivisionName>
<Plan Type="SingleFamily">
<PlanNumber>555</PlanNumber>
<PlanName>Pinewood</PlanName>
<BasePrice>200500.0000</BasePrice>
</Plan>
<Plan Type="MultiFamily">
<PlanNumber>444</PlanNumber>
<PlanName>Westfield</PlanName>
<BasePrice>270000.0000</BasePrice>
</Plan>
Note: There can be multiple Subdivisions in my XML document. I'm just showing one in my example for the sake of brevity.
My final output is the same as the input except that a PriceLow attribute has been added to the Subdivision element containing the minimum BasePrice of all Plans who are siblings of the Subdivision:
<Subdivision Status="Active" PriceLow="200500.00"> <==== ADDED!!!
<SubdivisionName>Chesla</SubdivisionName>
<Plan Type="SingleFamily">
<PlanNumber>555</PlanNumber>
<PlanName>Pinewood</PlanName>
<BasePrice>200500.00</BasePrice>
</Plan>
<Plan Type="MultiFamily">
<PlanNumber>444</PlanNumber>
<PlanName>Westfield</PlanName>
<BasePrice>270000.00</BasePrice>
</Plan>
My incomplete xsl file looks like this:
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Subdivision">
... something goes here ...
</xsl:template>
Could someone help me complete this XSLT file? I'm reading a few books on XSLT, but in the meantime I need to complete this project soon.
Cheers, Bret