Utilizing CSS for showcasing XSTL table

I've hit a roadblock with my initial XML project and I need some help. My goal is to create an address book using an XML file containing contact data, which is then transformed in XSLT. While both the XML and XSLT files function correctly, I encounter issues when trying to incorporate my CSS file into the XSLT for formatting the page to match our website's design. Once the CSS is added, my table only displays the first row specified in the XSLT and halts. Below are the three code files provided along with the outcome after including the CSS file.

XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="contactdata.xsl"?>

<!DOCTYPE addressbook [
<!ELEMENT addressbook (contact)>
<!ELEMENT contact (fname,lname,mi,staddress,city,state,zip,phone,email,twitter)>
<!ELEMENT fname (#PCDATA)>
<!ELEMENT lname (#PCDATA)>
<!ELEMENT mi (#PCDATA)>
<!ELEMENT staddress (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT zip (#PCDATA)>
<!ELEMENT phone (#PCDATA)>
<!ELEMENT email (#PCDATA)>
<!ELEMENT twitter (#PCDATA)>
]>
<addressbook>
<contact>
<fname>Peyton</fname>
<lname>Manning</lname>
<mi>Z</mi>
<staddress>123 Go Vols</staddress>
<city>Denver</city>
<state>CO</state>
<zip>12345</zip>
<phone>1-800-youwish</phone>
<email><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16667b7778787f787156746479787579653875797b">[email protected]</a></email>
<twitter>peyton_manning</twitter>
</contact>

<contact>
<fname>Eric</fname>
<lname>Berry</lname>
<mi>P</mi>
<staddress>123 Arrowhead Stadium</staddress>
<city>Kansas City</city>
<state>MO</state>
<zip>34567</zip>
<phone>816-213-4452</phone>
<email><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2441464156565d64474c4d4142570a474b49">[email protected]</a></email>
<twitter>eric_berry</twitter>
</contact>
</addressbook>

XSLT:

<?xml-stylesheet type="text/css" href="sitetemplate.css"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>


 <xsl:template match="/*">
    <html>
        <body>
            <table>
                <tr>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Middle Initial</th>
                    <th>Street Address</th>
                    <th>City</th>
                    <th>State</th>
                    <th>Zip</th>
                    <th>Phone</th>
                    <th>Email</th>
                    <th>Twitter</th>
                </tr>
                <xsl:apply-templates/>
            </table>
        </body>
    </html>
 </xsl:template>

 <xsl:template match="contact">
  <tr><xsl:apply-templates/></tr>
 </xsl:template>

 <xsl:template match="contact/*">
  <td><xsl:value-of select="."/></td>
 </xsl:template>
</xsl:stylesheet>

CSS:

.text {font-family: Helvetica, Times, serif; color:white;}

.center {text-align:center;}

body {background-image:url('wallpaper.jpg'); font-family: Helvetica, Times, serif;}

hr {border: 0; width: 50%; color:white;}

table, th, td {border:10px white; background-color:blue; color:white;} 


a:link {color:#75B8FA; text-decoration:none;}
a:visited {color:#75B8FA; text-decoration:none;}
a:hover {color:#75B8FA; text-decoration:none;}
a:active {color:#FFFFFF; text-decoration:none;}

The issue persists even after incorporating the CSS: (Since image posting is restricted until I reach a certain rep on StackOverflow.)

Answer №1

If your CSS file can be found at: http://myUrl.com/myCSS.css, then you should include the following code in your transformation, right after <html>:

<head>
          <link rel="stylesheet"
                type="text/css"
                href="http://myUrl.com/myCSS.css"/>
        </head>

Alternatively, you can generate the styles inline like this:

<head>
          <style>
                    .text {font-family: Helvetica, Times, serif; color:white;}
                    .center {text-align:center;}
                    body {background-image:url('wallpaper.jpg'); font-family: Helvetica, Times, serif;}
                    hr {border: 0; width: 50%; color:white;}
                    table, th, td {border:10px white; background-color:blue; color:white;}
                    a:link {color:#75B8FA; text-decoration:none;}
                    a:visited {color:#75B8FA; text-decoration:none;}
                    a:hover {color:#75B8FA; text-decoration:none;}
                    a:active {color:#FFFFFF; text-decoration:none;}
          </style>
        </head>

Another option is to generate the necessary processing instruction:

Add the following code (right before <html>):

<?xml-stylesheet type="text/css" href="sitetemplate.css"?>

This will add the necessary styling to your document automatically.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

As the screen size decreases, stacked Font Awesome icons seem to vanish

Currently, I'm designing a form that requires the user to select a color scheme by clicking on circle font awesome icons. These icons are implemented using Bootstrap and when clicked, a stacked font-awesome icon appears. However, I've encountered ...

Using JQuery selectors to locate elements with or without child elements

Below is a demonstration of HTML code: <div class="container"> <div class="zone"> <img class="thumb" alt="GG"> </div> <div class="zone"> <span>&nbsp;</span> </div> <div cl ...

Shifting the pagination outside of the slider in ReactJS and SwiperJS seems to be tricky. Despite trying to adjust the margins and padding, the pagination

I've been struggling with this issue for a while now. I need to move the pagination outside of the slider, but using padding or margin doesn't seem to work. It always remains inside the slider, and if I try to position it outside, it gets hidden. ...

Looking for assistance with deleting a child element in an XML file using PHP

I need help figuring out how to delete a child from my jobs.xml file with a PHP script. My jobs.xml file looks like this: <jobs> <event jobid="1"> <title>jobtitle</title> <desc>description</desc> &l ...

The malfunction of CSS3 effect

I designed a website and used DIV CSS to call an image. .header_bottom_area { background: url(../img/HomepagePanels.jpg)no-repeat scroll center center; max-width: 100%; width: auto; height: 911px; } I would like to have the same image as shown in ...

The method I used to position a triangle at the bottom border of a parent element with relative

https://i.stack.imgur.com/RZjJ9.png I am trying to achieve a centered triangle within a border, but I am facing a challenge due to the parent component being relative. When I remove the relative positioning, I struggle to position the triangle in the cent ...

Using PHP to Determine Similarity of Attribute Names in Two XML Files

I have two XML files named string1.xml and string2.xml, each file containing multiple lines of code. My goal is to compare the two XML files based on the presence of the same attribute names. I intend to iterate through all the lines using the following l ...

Nested CSS selector within a parent element

How can I change the color of both elements inside a custom button when the button is active? The first color is defined by the class of the button, and the second color is defined by the class of the span inside that button. CSS: .buttonClass{ color:b ...

The dropdown feature fails to function properly when contained within a Bootstrap Popover

Utilizing jQuery v1.12.4, Bootstrap v3.3.7 and Bootstrap-Select v1.10.0. In a popover, I have 2 components. When the popover is opened, I am able to interact with the dropdowns but the selection does not change when clicking an option. You can view the e ...

How to use multiple class names with Next.js module CSS

Currently, in my project I am utilizing Next.js along with module.css. However, I have encountered an issue. There is a "button" component nested inside another component. I am trying to apply both a normal className and Style.myClass to this button compon ...

What is the best way to calculate the total from a call-template in XSLT?

Looking at some XML code like this; <risk> <driver driverId="2"> <vehicleUse>M</vehicleUse> </driver> <driver driverId="3"> <vehicleUse>F</vehicleUse> </driver> <driver driverId="4 ...

Hide popup using HTML when clicking outside of it

Currently, I have implemented Bootstrap Popover with HTML content using the code snippet below. This code is based on the answer provided at . $(".song-status-link").popover({ html: true, placement: 'bottom', ...

Unable to access 'read more' link in WordPress post - seeking solution

Is there a way to move the "read more" link to the end of the post on my blog homepage? Currently, all the content of the post is displayed on my homepage. I want to restrict the characters shown and have the link at the end. Thank you! ...

Utilizing Bootstrap grid system to create varied column widths for content alignment

Looking to create a page with multiple entries that include text descriptions and associated icons of varying sizes, aligned neatly. (For simplicity, using letters "i" and "w" as placeholders for icons.) For wider screens, the setup should feature a grid ...

ErrorPlacement in jQuery validation is causing an issue where errors cannot be removed even after they have been corrected

Can you assist me in resolving an issue? I am struggling with removing an error message once a user has corrected their mistake, particularly when it comes to validating an email field. The error keeps getting added multiple times until validation is succe ...

Styling text using SVG in HTML

I'm trying to underline a text element in SVG using the text-decoration attribute, but I'm running into an issue with the color of the line not changing. Here is the code snippet I am working with: <svg id="svg" viewBox="0 0 300 ...

Expanding content will not cause Flexbox to stretch

I am facing an issue with a container that includes a header tag and a div. The height of the div is set to 100vh, causing it to consume all available space. Within the div, there are two additional divs. Everything works as expected until I add more conte ...

Include an Open OnClick event in the React/JSX script

We have a dynamic menu created using JavaScript (React/JSX) that opens on hover due to styling. My inquiries are: Instead of relying on CSS for the hover effect, where in the code can I implement an OnClick event to trigger the menu opening using Java ...

Child element failing to resize along with parent container

Here is the HTML structure I have for a template.php page within my website. <!DOCTYPE html> <html lang="en"> <head> <title></title> ...... </head> <body> <div id="container"> ...

Unable to select selectbox in the bottom section of Safari browser

There seems to be an issue with the selectbox being unselectable at the lower part in Safari. It's difficult to pinpoint the exact problem in the code. You can see the issue on the country selectbox by visiting this website: <span> <sp ...