Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [XSLT] problem z transformacja
e1n
post
Post #1





Grupa: Zarejestrowani
Postów: 20
Pomógł: 0
Dołączył: 12.06.2002
Skąd: Koszalin/Toruń

Ostrzeżenie: (0%)
-----


Witam !

Mam nastepujący problem . Zalozmy ze mam nastepujacy dokument z moim meta
jezykiem :

  1. <metalanguagae>
  2. <ara>
  3. some content
  4. </para>
  5. <heading level="1"> qwerty</heading>
  6. <heading level="3">qwerty2</heading>
  7. <ara>fasdfas</para>
  8. <sth>fdaf<s/th>
  9. <heading level="1">qwerty3</heading>
  10. </metalanguage>


Pisze do niego transformacje , ktora przeksztalca go na XHTML w taki sposob ze
element <heading level="1"> przechodzi na <h1> itd.
Jednak zalezy mi z pewnych wzgledow zeby do kazdego wynikowego <h1> ,<h2> itd
dodwac atrybut id ktory zawiera liczbe wskazujaca na to ktory to element
heading czyli :
XHTML:
  1. <p>
  2. some content
  3. </p>
  4. <h1 id="1">qwerty</h1>
  5. <h3 id="2">qwerty2</h3>
  6. <>fasdfas</p>
  7. <sth>fdaf</sth>
  8. <h1 id="3">qwerty3</h1>


jak to zrobic w XSL'u ?
Znalezlem jakis wzorzec na iteracje ale on sie nie sprawdza do numeracji tych
samych elementow. Potem probowalem w ten sposob :

  1. xsl:template match="heading">
  2. <xsl:choose>
  3. <xsl:when >test='@level="1"'>
  4. <h1>
  5. <xsl:attribute name="id">
  6. <xsl:text>toc</xsl:text>
  7. <xsl:number value="position() - 1" format="1" />
  8. </xsl:attribute>
  9. <xsl:apply-templates />
  10. </h1>
  11. </xsl:when>
  12. <xsl:when >test='@level="2"'>
  13. <h2>
  14. <xsl:attribute name="id">
  15. <xsl:text>toc</xsl:text>
  16. <xsl:number value="position() - 1" format="1" />
  17. </xsl:attribute>
  18. <xsl:apply-templates />
  19. </h2>
  20. </xsl:when>
  21. <xsl:when >test='@level="3"'>
  22. <h3>
  23. <xsl:attribute name="id">
  24. <xsl:text>toc</xsl:text>
  25. <xsl:number value="position() - 1" format="1" />
  26. </xsl:attribute>
  27. <xsl:apply-templates />
  28. </h3>
  29. </xsl:when>
  30. <xsl:when >test='@level="4"'>
  31. <h4>
  32. <xsl:attribute name="id">
  33. <xsl:text>toc</xsl:text>
  34. <xsl:number value="position() - 1" format="1" />
  35. </xsl:attribute>
  36. <xsl:apply-templates />
  37. </h4>
  38. </xsl:when>
  39. <xsl:when >test='@level="5"'>
  40. <h5>
  41. <xsl:attribute name="id">
  42. <xsl:text>toc</xsl:text>
  43. <xsl:number value="position() - 1" format="1" />
  44. </xsl:attribute>
  45. <xsl:apply-templates />
  46. </h5>
  47. </xsl:when>
  48. <xsl:when >test='@level="6"'>
  49. <h6>
  50. <xsl:attribute name="id">
  51. <xsl:text>toc</xsl:text>
  52. <xsl:number value="position() - 1" format="1" />
  53. </xsl:attribute>
  54. <xsl:apply-templates />
  55. </h6>
  56. </xsl:when>
  57. </xsl:choose>
  58. </xsl:template>


Okazal sie byc on prawie dobry ale XPath'owe position() zwraca pozycje w
strukturze dokumentu a nie w odniesieniu do tych samych elementow i w ten
sposob liczby jakie sa przyporzadkowywane nie sa kolejnymi liczbami
naturalnymi

Czy ktos ma jakis pomysl jak to zrobic ?


--------------------
Wszyscy wiedzą, że czegoś nie da się zrobić, i przychodzi taki jeden, który nie wie, że się nie da, i on właśnie to robi.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 00:33