What is the first citation of the well-known story? I have seen it adapted in both a Chinese and an ambiguously European setting. Is the eponymous emperor supposed to be the HRE's Kaiser? Chinese Emperor? Byzantine Baselius?
This story is an invention of Hans Christian Andersen (1805-1875). It is not a "folk tale" in the strict sense of the word in that it was not part of any oral tradition - although it was inspired to some degree by a Spanish source that may have had some life as folklore. It is a literary device crafted to imitate a folktale, and so it would be better to term it a "fairytale." One would need to look at the original Christiansen text to see what he intended for the setting, but from what I gather, is intent was a European court.
To clarify on definitions, here is an excerpt of my Introduction to Folklore, which I will e-publish in September:
Folktales – or Märchen, again using the German, technical term – are longer stories with more than one episode. They are restricted, in theory at least, to evening presentation. A folktale is not to be believed, taking place in a fantastic setting. The European folktale also requires a happy ending, the cliché of “happily ever after.” Any given folktale can be told with considerable variation, but they are traditional in basic form, and folklorists have spent decades tracing the history and distribution of these stories.
A word here about the term “fairytale” is appropriate. At the end of the eighteenth century, various writers, most prominently the Grimm brothers, began publishing children’s stories based on folktales. These collections became extremely popular, particularly among the urban and increasingly literate emerging middle class as it found itself removed from the peasant soil that served as home to the stories. Fairytales often cause misunderstandings. In a culture that knows more about fairytales than Märchen, people assume that the folktale was intended for children. This is certainly not the case since the stories were often violent or sexual in ways thought inappropriate for children. Indeed, the telling of a folktale was usually delayed until the children had gone to bed. While fairytales provide the modern reader with the easiest access to the many stories that were once told internationally, one should always realize that they are removed from the primary inspiration. The original stories and their content provided serious entertainment for adults and they were part of an oral tradition, not something that was fossilized in writing.
The evolution of fairytales had a profound effect on the subject of fairies, elves, trolls, and similar entities. Because fairytales became the literary domain of children, many people – including writers and publishers – assumed the same was true of the supernatural beings. In their original context, nothing could be further from the truth. These were not cute, diminutive creatures whose sole purpose was to delight children. They were powerful, dangerous, and capable of great harm. The European peasantry feared and respected them, and their stories underscore this, conveying in uncompromising terms the code of ethics and behavior that one must employ to survive an encounter with the dangerous world of magic and power.