code_junkie

Use XSL to generate dynamic XSL that is executed within the same script?

Nov 12th, 2011
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <xsl:for-each select="//constants/constant" >
  2. <xsl:variable >
  3. <xsl:attribute name="name">
  4. <xsl:value-of select="@name"/>
  5. </xsl:attribute>
  6. <xsl:attribute name="select">
  7. <xsl:value-of select="@value"/>
  8. </xsl:attribute>
  9. </xsl:variable>
  10. </xsl:for-each>
  11.  
  12. xsl:namespace-alias
  13.  
  14. <v name="myVarName">myValue</v>
  15.  
  16. <resgroup id="constants" >
  17. <resbundle>
  18. <res id="var1">var1Value</res>
  19. </resbundle>
  20. <resbundle>
  21. <res id="var2">var2Value</res>
  22. </resbundle>
  23. </resgroup>
  24.  
  25. <resgroup id="constants" >
  26. <resbundle>
  27. <res id="var1">var1Value</res>
  28. </resbundle>
  29. <resbundle>
  30. <res id="var2">var2Value</res>
  31. </resbundle>
  32. </resgroup>
  33.  
  34. <xsl:stylesheet
  35. version="1.0"
  36. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  37. xmlns:metaxsl="my:metaxsl"
  38. exclude-result-prefixes="metaxsl"
  39.  
  40. <xsl:namespace-alias result-prefix="xsl" stylesheet-prefix="metaxsl" />
  41.  
  42.  
  43. <xsl:template name="BuildInstantiateConstantsTemplate_tmpl">
  44. <metaxsl:template match="/" name="instantiateConstants_tmpl">
  45. <metaxsl:template>
  46. <xsl:for-each select="//resgroup[@id='constants']/resbundle/res">
  47. <metaxsl:variable>
  48. <xsl:attribute name="name">
  49. <xsl:value-of select="@id" />
  50. </xsl:attribute>
  51. <xsl:attribute name="select">
  52. <xsl:value-of select="text()" />
  53. </xsl:attribute>
  54. </metaxsl:variable>
  55. </xsl:for-each>
  56. </metaxsl:template>
  57. </metaxsl:template>
  58. </xsl:template>
  59.  
  60.  
  61. <xsl:template match="/">
  62. <xsl:call-template name="BuildInstantiateConstantsTemplate_tmpl" />
  63. </xsl:template>
Add Comment
Please, Sign In to add comment