Академический Документы
Профессиональный Документы
Культура Документы
txt
**
** Example code snippets for XML Essential Training
*/
----------------------------------------------------------
CHAPTER 4: WORKING WITH XML
--- First XML File
<FirstTag>
This is our first XML file
<!-- This is a comment in the file -->
</FirstTag>
--- XML and CSS
<?xml-stylesheet type="text/css" href="FirstXMLFile.css"?>
FirstTag
{
display : block;
font-family : Arial;
font-size : large;
color : Blue;
}
--- Styling Tags with CSS
<?xml-stylesheet type="text/css" href="businesscard.css"?>
Name {
color: #0D3427;
font-weight: bold;
font-size: 140%;
display: block;
margin-bottom: 3%;
}
phone {
font-size: 90%;
color: #523819;
font-size: 90%;
display: block;
}
email {
color: #0D3427;
font-size: 90%;
font-weight: bold;
display: block;
margin-top: 3%;
}
--- Advanced XML with CSS
<?xml-stylesheet type="text/css" href="businesscard_CSS2.css"?>
Name {
color: #0D3427;
font-weight: bold;
font-size: 140%;
display: block;
margin-bottom: 3%;
}
email {
color: #0D3427;
font-size: 90%;
font-weight: bold;
display: block;
margin-top: 3%;
}
email:before {content: "e-mail: "}
phone {
font-size: 90%;
color: #523819;
font-size: 90%;
display: block;
}
phone:before {content: attr(type) ": "}
phone[primary]:after {content: " (" attr(primary) ")"}
function hideEmail() {
document.getElementById("email").style.display = 'none';
}
function showEmail() {
document.getElementById("email").style.display = '';
}
window.addEventListener("load", populateFields);
--- Creating New Document Content
// for each business card, loop over its tags an
d create a new <div> to
// each card along with the information for all
the fields
for (var i=0; i < bizCards.length; i++) {
var currentCard = bizCards[i]; // store a re
ference to the current <BusinessCard>
// make a new <div> for the whole card
var newCard = document.createElement("div");
newCard.setAttribute("className","BusinessCa
rd");
newCard.setAttribute("class","BusinessCard")
;
// now create a <div> for the name
var newName = document.createElement("div");
newName.setAttribute("className","Name");
newName.setAttribute("class","Name");
var nameStr = document.createTextNode(curren
tCard.getElementsByTagName("Name")[0].firstChild.data);
newName.appendChild(nameStr);
newCard.appendChild(newName);
// create separate <divs> for the phones
var phones = currentCard.getElementsByTagNam
e("phone");
var newPhone;
for (var j=0; j < phones.length; j++) {
newPhone = document.createElement("div")
;
newPhone.setAttribute("className","phone");
newPhone.setAttribute("class","phone");
var labelStr = currentCard.getElementsByTagN
ame("phone")[j].getAttribute("type") + ": ";
var phoneStr = document.createTextNode(label
Str + currentCard.getElementsByTagName("phone")[j].firstChild.data);
newPhone.appendChild(phoneStr);
newCard.appendChild(newPhone);
}
// create a <div> for the email
var newEmail = document.createElement("div")
;
newEmail.setAttribute("className","email");
newEmail.setAttribute("class","email");
var emailStr = document.createTextNode("emai
l: " + currentCard.getElementsByTagName("email")[0].firstChild.data);
newEmail.appendChild(emailStr);
newCard.appendChild(newEmail);
// now add the new <div> containing the card info to the
web page
document.getElementsByTagName("body")[0].app
endChild(newCard);
}
<xsl:choose>
<xsl:when test="@available = 'no'">
<h1 style="color:#8A8A8A">
<img style="border:0; margin-left:10px">
<xsl:attribute name="src">
<xsl:value-of select="photo"/>
</xsl:attribute>
</img>
<xsl:value-of select="name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="type"/>
</h1>
</xsl:when>
<xsl:when test="@available = 'soon'">
<h1 style="color:#000077">
<img style="border:0; margin-left:10px">
<xsl:attribute name="src">
<xsl:value-of select="photo"/>
</xsl:attribute>
</img>
<xsl:value-of select="name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="type"/>
</h1>
</xsl:when>
<xsl:otherwise>
<h1 style="color:#0D3427">
<img style="border:0; margin-left:10px">
<xsl:attribute name="src">
<xsl:value-of select="photo"/>
</xsl:attribute>
</img>
<xsl:value-of select="name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="type"/>
</h1>
</xsl:otherwise>
</xsl:choose>