Вывод неразрывного пробела при формирование html с помощью xmltransform (outputting nbsp to HTML when use xmltransform)
пятница, 9 апреля 2010 г.
Оставить комментарий
При формировании HTML, в котором используется неразрывный пробел надо учесть пару особенностей:
- Для вывода надо использовать команду
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00118: Warning: undefined entity "nbsp"
Error at line 1
поэтому преобразование должно вернуть не xml, а clob или varchar2, для этого необходимо использовать функцию getclobval().
Пример:
select xmltransform(xmldata.depts,
xmltype('<?xml version="1.0" encoding="Windows-1251"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<table border="1" cols="3">
<xsl:for-each select="/DEPARTMENTS/DEPARTMENT">
<tr><td><xsl:value-of select="@DEPTNO"/></td>
<td colspan="2"><xsl:value-of select="@DNAME"/></td>
</tr>
<xsl:for-each select="EMPLOYEE">
<tr><td><xsl:value-of select="EMPNO"/></td>
<td><xsl:value-of select="ENAME"/></td>
<td><xsl:value-of select="JOB"/></td>
</tr>
</xsl:for-each>
<xsl:if test="position() != last()">
<tr><td colspan="3">
<xsl:text disable-output-escaping="yes">&nbsp;</xsl:text>
</td></tr>
</xsl:if>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>')
).getclobval()
from (
select xmlelement(departments, xmlagg(
xmlelement(department,
xmlattributes(emp.deptno,
(select dname from dept where deptno = emp.deptno) as dname),
xmlagg(xmlelement(employee,
xmlforest(emp.empno, emp.ename, emp.job))
))
)) as depts
from emp
group by emp.deptno
) xmldata
Результат:
<?xml version="1.0" encoding="UTF-8"?>
<html>
<body>
<table border="1" cols="3">
<tr>
<td>10</td>
<td colspan="2">ACCOUNTING</td>
</tr>
<tr>
<td>7782</td>
<td>CLARK</td>
<td>MANAGER</td>
</tr>
<tr>
<td>7839</td>
<td>KING</td>
<td>PRESIDENT</td>
</tr>
<tr>
<td>7934</td>
<td>MILLER</td>
<td>CLERK</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td>20</td>
<td colspan="2">RESEARCH</td>
</tr>
<tr>
<td>7369</td>
<td>SMITH</td>
<td>CLERK</td>
</tr>
<tr>
<td>7902</td>
<td>FORD</td>
<td>ANALYST</td>
</tr>
<tr>
<td>7876</td>
<td>ADAMS</td>
<td>CLERK</td>
</tr>
<tr>
<td>7788</td>
<td>SCOTT</td>
<td>ANALYST</td>
</tr>
<tr>
<td>7566</td>
<td>JONES</td>
<td>MANAGER</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td>30</td>
<td colspan="2">SALES</td>
</tr>
<tr>
<td>7499</td>
<td>ALLEN</td>
<td>SALESMAN</td>
</tr>
<tr>
<td>7698</td>
<td>BLAKE</td>
<td>MANAGER</td>
</tr>
<tr>
<td>7654</td>
<td>MARTIN</td>
<td>SALESMAN</td>
</tr>
<tr>
<td>7844</td>
<td>TURNER</td>
<td>SALESMAN</td>
</tr>
<tr>
<td>7900</td>
<td>JAMES</td>
<td>CLERK</td>
</tr>
<tr>
<td>7521</td>
<td>WARD</td>
<td>SALESMAN</td>
</tr>
</table>
</body>
</html>
0 коммент. »
Оставьте Ваш комментарий