Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

XSLT foreach wrong value

I am having some difficulty selecting the correct value in my loop.
my loop does not retrieve the associated values.

Resume of File.xml

<WKIUserSpecifiedAttributesRoot>
            <EntityRef Ref_ID="ID_17">
                <Attribute name="Difficulty" >
                    <Value>Low</Value>
                </Attribute>
                <Attribute name="Title" >
                    <Value> 5 </Value>
                </Attribute>
            </EntityRef>
            <EntityRef Ref_ID="ID_19">
                <Attribute name="Difficulty" >
                    <Value>hight</Value>
                </Attribute>
                <Attribute name="Title" >
                    <Value> 10 </Value>
                </Attribute>
            </EntityRef>
</WKIUserSpecifiedAttributesRoot>

file.xslt

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<xsl:for-each select="$P_DataXMLRoot/WKIPreviewDataRoot/WKIUserSpecifiedAttributesRoot/EntityRef">
   <xsl:value-of select="//Attribute[@name = 'Title']" />
   <xsl:value-of select="//Attribute[@name = 'Difficulty']" />
 </xsl:for-each>

I recover many values ​​but not the one that corresponds to the Ref_Id, All my data are the same.
I only provide 2 Entity_Refs in the example but I have many more but only the value of the first Entity_Ref appears in all the results of the loop.

Thank you Verry Much.

>Solution :

From the posted XML, you would want something like this :

<xsl:for-each select="$P_DataXMLRoot/WKIUserSpecifiedAttributesRoot/EntityRef">
  <xsl:value-of select="Attribute[@name = 'Title']/Value" />
  <xsl:value-of select="Attribute[@name = 'Difficulty']/Value" />
</xsl:for-each>

Using // goes back to the beginning of your document and traverses it to find all elements corresponding to your XPath.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading