I have two datatypes…
So, I had an idea... Maybe I should change the Subject fields in the “Courses” datatype from "Data Reference” to “Unique Identifier (GUID)” and use a “Selector” widget type under the advanced tab. Then I would link off to a custom XSLT function, instead of the automatically generated “GetSubjectsXml”. My new function contained the following template:
Does anyone have any idea how to get this to work?
- The first “Subjects” datatype has three fields: Id, SubjectLevel (data reference), SubjectName (string 64 – used as title field in lists). The SubjectLevel field has one of two values: “undergraduate” and “postgraduate”, and is used to distinguish between “Undergraduate Art” and “Postgraduate Art”
-
The second “Courses” datatype has many fields, including two Subject (data reference) fields. A course can be made up of one or two subjects.
- Art
- Art
- Design
-
Design
So, I had an idea... Maybe I should change the Subject fields in the “Courses” datatype from "Data Reference” to “Unique Identifier (GUID)” and use a “Selector” widget type under the advanced tab. Then I would link off to a custom XSLT function, instead of the automatically generated “GetSubjectsXml”. My new function contained the following template:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" xmlns:lang="http://www.composite.net/ns/localization/1.0" xmlns:f="http://www.composite.net/ns/function/1.0" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xsl in lang f">
<xsl:template match="/">
<xsl:if test="/in:inputs/in:result[@name='GetSubjectsXml']/Subjects">
<SubjectsElements>
<xsl:apply-templates select="/in:inputs/in:result[@name='GetSubjectsXml']/Subjects">
<xsl:sort select="SubjectLevel.EducationLevel" order="ascending" />
</xsl:apply-templates>
</SubjectsElements>
</xsl:if>
</xsl:template>
<xsl:template match="/in:inputs/in:result[@name='GetSubjectsXml']/Subjects">
<Subjects>
<xsl:attribute name="Id">
<xsl:value-of select="@Id" />
</xsl:attribute>
<xsl:attribute name="SubjectName">
<xsl:value-of select="@SubjectLevel.EducationLevel" />
<xsl:text> - </xsl:text>
<xsl:value-of select="@SubjectName" />
</xsl:attribute>
</Subjects>
</xsl:template>
</xsl:stylesheet>
... which produces something clean like:<SubjectsElements xmlns="http://www.w3.org/1999/xhtml">
<Subjects Id="08b98af7-d72d-415b-8906-6a27d253b90b" SubjectName="Undergraduate - Art"/>
<Subjects Id="483a7fe9-8a9f-4c36-8024-e2c772bab932" SubjectName="Postgraduate - Art"/>
<Subjects Id="95dabec6-69b7-4744-9f65-c048ec994cd2" SubjectName="Undergraduate - Design"/>
<Subjects Id="d2f291c3-4a1a-4cca-8cfa-f3986922ed8a" SubjectName="Postgraduate - Design"/>
</SubjectsElements>
This should allow me to have a dropdown with:- Undergraduate - Art
- Undergraduate - Design
- Postgraduate - Art
-
Postgraduate - Design
Does anyone have any idea how to get this to work?