<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<style type="text/css">
/* 내부 CSS 스타일을 정의합니다. */
body {
font-family: Arial, sans-serif;
}
table {
border-collapse: collapse;
width: 80%;
margin: 20px auto;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
h1 {
text-align: center;
}
</style>
</head>
<body>
<h1>학생 정보</h1>
<table>
<tr>
<th>학번</th>
<th>이름</th>
<th>성별</th>
<th>나이</th>
<th>전공</th>
</tr>
<xsl:for-each select="학생정보/학생">
<tr>
<td><xsl:value-of select="학번"/></td>
<td><xsl:value-of select="이름"/></td>
<td><xsl:value-of select="성별"/></td>
<td><xsl:value-of select="나이"/></td>
<td><xsl:value-of select="전공"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
#### Breakdown of the XSLT Stylesheet:
- `<?xml version="1.0" encoding="UTF-8"?>`: The XML declaration specifies this file as an XML document encoded in UTF-8.
- `<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">`: Defines the document as an XSLT stylesheet, using version 1.0 of XSLT. The `xmlns:xsl` attribute declares the XSLT namespace required to use XSLT elements.
- `<xsl:template match="/">`: The template match attribute is set to `/`, indicating that the template applies to the entire XML document. This is the starting point for the transformation.
#### HTML Structure:
- The XSLT template generates a basic HTML document structure with `<html>`, `<head>`, and `<body>` elements.
- Within the `<head>`, a `<style>` element contains CSS rules to style the output HTML. These styles set font families, control table appearance, and align text.
- The `<body>` contains a heading (`<h1>`) labeled "학생 정보" (Student Information) and a `<table>` structured to display student data in rows and columns with headers for student ID, name, gender, age, and major.
#### Data Processing:
- `<xsl:for-each select="학생정보/학생">`: This instruction iterates over each `<학생>` (student) element within the `<학생정보>` (student information) root element of the source XML.
- `<xsl:value-of select="학번"/>` (and similar for 이름, 성별, 나이, 전공): Extracts and inserts the text of each specified element (e.g., student ID, name, gender, age, major) into table cells (`<td>`).
#### Summary:
This XSLT stylesheet is crafted to transform structured XML data about students into a visually appealing HTML table, making the information easily readable and accessible. By specifying how each XML element should be presented in HTML format, it enables automated and dynamic generation of web content from XML data sources, illustrating the power of XSLT for web data presentation and reporting.
'개념 > HTML+CSS' 카테고리의 다른 글
HTML) Exploring Font Styles and Effects in CSS (0) | 2025.02.04 |
---|---|
HTML) background style type (0) | 2025.02.03 |
HTML) CSS Styling Showcase (0) | 2025.02.02 |
HTML) Web font (0) | 2025.02.01 |
HTML) Using @font-face for Custom Fonts in HTML5 (0) | 2025.01.31 |