xml - Exit from parent loop is not working in XSLT -
i 1 output when condition met. here sample xml.
<school> <student_details> <student> <id>1</id> <name>manju</name> <subject> <subject_name>english</subject_name> </subject> <subject> <subject_name>maths</subject_name> </subject> </student> <student> <id>2</id> <name>raghu</name> <subject> <subject_name>social</subject_name> </subject> <subject> <subject_name>maths</subject_name> </subject> </student> <student> <id>3</id> <name>vijay</name> <subject> <subject_name>maths</subject_name> </subject> </student> <student> <id>4</id> <name>sunil</name> <subject> <subject_name>social</subject_name> </subject> </student> <student> <id>5</id> <name>anil</name> <subject> <subject_name>social</subject_name> </subject> <subject> <subject_name>english</subject_name> </subject> <subject> <subject_name>kannada</subject_name> </subject> </student> </student_details> <exclude> <exclude_subjects> <subject_name>english</subject_name> </exclude_subjects> <exclude_subjects> <subject_name>maths</subject_name> </exclude_subjects> </exculde> </school>
here xsd:
<schema> <element name="school"> <complextype> <sequence> <element name="student_details> <complextype> <sequence> <element name="student" maxoccurs="unbounded"> <complextype> <sequence> <element name="id" type="sting"/> <element name="name" type="sting"/> <element name="subject" maxoccurs="unbounded"> <complextype> <sequence> <element name="subject_name" type="sting"/> </complextype> </sequence> </element> </complextype> <sequence> </element> </complextype> <sequence> </element> <element name="exclude"> <complextype> <sequence> <element name="exclude_subjects" maxoccurs="unbounded"> <complextype> <sequence> <element name="subject_name" type="sting"/> </complextype> </sequence> </element> </complextype> <sequence> </element> </complextype> <sequence> </element> </schema>
here xslt not working
<xsl:template match="/"> <ns0:xsl:output> <xsl:for-each select="/ns0:school/ns0:exclude/exclude_subjects> <variable name="a" select="position"/> <xsl:for-each select ="../../ns0:student_details/ns0:student"/> <xsl:for-each select="ns0:subject[not(./ns0:subject_name = ../../../ns0:exclude/ns0:exclude_subjects[$a]/ns0:subject_name)]][1]"> <ns0:result> <xsl:copy-of select="../ns0:name"/> </ns0:result> </ns0:output> </xsl:template>
my requirement if student contains subject not there in exclude_subjects, student name should assigned target without duplicate.
for eg: in above given sample xml,raghu,anil n sunil names should assigned target.
please help....
try way?
xslt 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:key name="exclude" match="exclude_subjects" use="subject_name" /> <xsl:template match="/school"> <output> <xsl:for-each select="student_details/student[subject[not(key('exclude', subject_name))]]"> <xsl:copy-of select="name"/> </xsl:for-each> </output> </xsl:template> </xsl:stylesheet>
result (after changing </exculde>
</exclude>
)
<?xml version="1.0" encoding="utf-8"?> <output> <name>raghu</name> <name>sunil</name> <name>anil</name> </output>
edit
currently using bpel 10g , xsl:key not supported in xslt.
then you're not using xslt. still, can achieve same result using less efficient method:
<xsl:template match="/school"> <output> <xsl:for-each select="student_details/student[subject[not(subject_name = ../../../exclude/exclude_subjects/subject_name)]]"> <xsl:copy-of select="name"/> </xsl:for-each> </output> </xsl:template>
Comments
Post a Comment