Jump to content

akuash

Members
  • Posts

    2
  • Joined

  • Last visited

akuash's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I am trying to write a document which could help in filtering data from another XML document. E.g. <filter> <what> <include> <marital_staus/> <ms>single</ms> <!--nog = no of groups--> <include> <memberofgroups/> <gn>Football club</gn> <!--user is a member of this club--> </include> </include> </what></filter> What I want this code to do is to choose, first, the users who are members of Football club, and then out of those, chose the users who are single. But I cannot figure out how to write a stylesheet for this. I wrote this: <xsl:template name="temp"> <xsl:param name="a1"/> <xsl:param name="pro"/> <xsl:choose> <xsl:when test="$op = 'marital_status'"> <xsl:for-each select="/document/users/user"> <xsl:if test="marital_status=$a1"> <xsl:value-of select="."/> </xsl:if> </xsl:for-each> </xsl:when> <xsl:when test="$op = 'memberofgroups'"> <xsl:for-each select="/document/users/user"> <xsl:for-each select="./groups/member_of_group"> <xsl:if test=".=$a1"> <xsl:value-of select="."/> </xsl:if> </xsl:for-each> </xsl:for-each> </xsl:when> </xsl:choose> </xsl:template> <xsl:template match="include"> <xsl:call-template name="temp"> <xsl:with-param name="a1"> <xsl:apply-templates select="*[2]"/> </xsl:with-param> </xsl:call-template> </xsl:template> While calling the template I pass the correct values I suppose. Problem is I get all the users who are single, plus all the users who are members of that particular group. However I want single users who are also member of Football club. I don't want the stylesheet to be hard-coded, because I also want to do filtering based on other elements. I can not figure out how can I save the filtered elements into something which could be used as an input for the next XPath expression. Or am I making some mistake while writing the constraints for filtering the document. Or could there be any other more appropriate way of writing a document for filtering? I will much appreciate your help. And I have one xml document "document" and two elements "filter" and "users".
  2. Hello EveryoneI have recently started learning XML and very much confused about the use of elements and attributes. I have read many articles and some rules of thumb but still unable to get a clear picture of when to use what. For example one good rule of thumb is to use single valued data as attributes and multiple valued data as elements. Another to represent data as elements and meta data as attributes. Some articles say describe several other approaches or rules. I have several questions in mind and will much appreciate if any one can help me in understanding1) What if the data is single valued ? Should I make it an attribute or an element. E.g. Marital Status of a person is single valued at the same time its data. What will be a difference in an attribute and element in such a case ? 2) For example Date of birth is also a single valued data but many forums suggested making separate elements for day month and year and some suggested making a date of birth element and day year and month its attributes. What is the difference How will either approach help ? 3) what is more useful for search operations and how ? If I want to design it in such a way that its more useful and efficient for searching what shall I do. For example what difference an element or an attribute of date of birth will make for a search operation I.e. if I want to search people born in 1980 or blah blah. I will much appreciate your help.Cheers
×
×
  • Create New...