XML Dom CSS
XML Dom CSS
XML Dom CSS
<Element attr="attributeValue">Text</Element>
<E A = "">Text</E>
<root>
"//contains(self, "")"
""
IXMLDOM
{IXMLDOMDocument/DOMDocument} - created by set objXmlDoc = CreateObje
ct("Microsoft.XMLDOM") -- {DOMDocument}
.parseError.errorCode
.parseError.reason
.documentElement -- root node has type IXMLDOMNod
e
{IXMLDOMElement} -
{IXMLDOMNode}
properties:
.nodeType -- see* there are 13 node types
supported by the MSXML parser
.nodeTypeString -- see* there are 13 node types supporte
d by the MSXML parser
.baseName -- r/o It returns the right-hand
side of a namespace-qualified name. For example, it returns "yyy" for the eleme
nt <xxx:yyy>. It always returns a nonempty string.
.nodeName -- see below
.nodeValue -- Contains the text associated
with the node.
.childNodes -- r/o see* returns IXMLDOMNodeL
ist with all node types. always returns IXMLDOMNodeList.
.firstChild -- r/o see*
.lastChild -- r/o see*
.nextSibling -- r/o see*
.previousSibling -- r/o see*
.prefix -- r/o Returns the namespace pre
fix. Read-only.used for asynchronous access
.parsed -- r/o Indicates the parsed stat
us of the node and child nodes. Read-only.
.parentNode -- r/o always returns NODE_ELEM
ENT node type (what about root node?)
.xml -- r/o XML representation of the
node and all its descendants., including <NodeName> ... </NodeName> for current
element
.text -- r/w see*, see nodeValue
.attributes -- r/o list of attributes for th
is node.
.ownerDocument -- r/o Returns the root of the document
{DOMDocument} that contains the node.
methods:
.appendChild(newChild) Appends a new child as the last
child of the node.
.cloneNode(deep); creates clone of current
node with all descedants (deep = true) or only with attributes (deep = false)
.hasChildNodes()
.insertBefore(newChild, refChild) -- if refChild == null t
hen its equal to .appendChild(newChild)
.removeChild(childNode) -- ex: {IXMLDOMD
ocument}.DocumentElement.RemoveChild(childNode)
.replaceChild(newChild, oldChild); if newChild = null then
its equal to removeChild(oldChild)
.selectNodes(xpath) Applies
the specified pattern-matching operation to this node's context and returns the
list of matching nodes as IXMLDOMNodeList.
.selectSingleNode(xpath) Applies the spec
ified pattern-matching operation to this node's context and returns the first ma
tching node.
.transformNode(objStylesheet) transform according to X
SLT style sheet. return string with result. see example below
.transformNodeToObject
IXMLDOMElement == IXMLDOMNode +
properties:
.tagName Contains the element nam
e. Read-only.
methods:
.getAttribute Gets the value of the attribute.
can be null
.getAttributeNode Gets the attribute node. can be
null
.getElementsByTagName Returns a list of all descendant element
s that match the supplied name.
.normalize Normalizes all descendan
t elements by combining two or more adjacent text nodes into one unified text no
de.
.removeAttribute Removes or replaces the named at
tribute.
.removeAttributeNode Removes the specified attribute from thi
s element
.setAttribute(name, value) Sets the value of the named attribute. i
f attribute not exist it will be created
.setAttributeNode Sets or updates the supplied att
ribute node on this element.
'=======================================================================
========================='
' IXMLDOMCharacterData does not directly correspond to any node type.
' Methods are reused by IXMLDOMCDATASection, IXMLDOMComment, IXMLDOMT
ext.
'=======================================================================
========================='
These methods handle large amounts of text, including sizes larger than
can be manipulated natively using string constructs.
props:
.data Stores the node data depending o
n the node type. Read/write.
.length Specifies the length, in charact
ers, of the data. Read-only.
methods:
.appendData(data) data - A
string containing the data that is to be appended to the existing string.
.deleteData(offset, count)
.replaceData(offset, count, data) Replaces the specified n
umber of characters with the supplied string.
.substringData(offset, data) Retrieves a substring of
the full string from the specified range.
.insertData(offset, data); Appends the supp
lied string to the existing string data.
'=======================================================================
========================='
if .nodeType is equal to: then .data returns:
'=======================================================================
========================='
NODE_CDATA_SECTION A string representing the text s
tored in the CDATA section.
NODE_COMMENT The content of the comment, excl
usive of the comment start and end sequence.
NODE_TEXT A string representing th
e text stored in the text node.
'===============================================================================
================='
transformNode : VBScript
'==============================================================================
=================='
set source = CreateObject("Msxml2.DOMDocument.6.0")
'OR set source = CreateObject("Microsoft.XMLDOM")
set stylesheet = CreateObject("Msxml2.DOMDocument.6.0")
'OR set stylesheet = CreateObject("Microsoft.XMLDOM")
source.setProperty("AllowDocumentFunction", true);
' Load data.
source.async = False
source.Load "d:\temp\hello.xml"
If (source.parseError.errorCode <> 0) Then
Set myErr = source.parseError
MsgBox("You have error " & myErr.reason)
Else
stylesheet.setProperty("AllowDocumentFunction", true);
' Load style sheet.
stylesheet.async = False
stylesheet.Load "d:\temp\hello.xsl"
If (stylesheet.parseError.errorCode <> 0) Then
Set myErr = stylesheet.parseError
MsgBox("You have error " & myErr.reason)
Else
' Do the transform. source is unchanged
strOutXml = source.transformNode(stylesheet)
MsgBox strOutXml
End If
End If
'==============================================================================
=================='
var xslt = new ActiveXObject("Msxml2.XSLTemplate.6.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");
var xslProc;
xslDoc.async = false;
xslDoc.load("sample2.xsl");
if (xslDoc.parseError.errorCode != 0) {
var myErr = xslDoc.parseError;
WScript.Echo("You have error " + myErr.reason);
} else {
xslt.stylesheet = xslDoc;
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
xmlDoc.async = false;
xmlDoc.load("books.xml");
if (xmlDoc.parseError.errorCode != 0) {
var myErr = xmlDoc.parseError;
WScript.Echo("You have error " + myErr.reason);
} else {
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
WScript.Echo(xslProc.output);
}
}
'==============================================================================
=================='
'==============================================================================
=================='
node can be created by:
{IXMLDOMNode}.cloneNode(deep);
importNode Clones a node from a different DOM object.
NodeType has properties
NODE_ELEMENT .NodeName name of the XML
tag, with any namespace prefix included if present.
NODE_TEXT .NodeValue
xml can be loaded as:
{IXMLDOMDocument}.load(xmlSource); xmlSource - An indicator of the
source XML to parse.
This may be an URL (String/BSTR), a Request object (in an ASP page),
an IStream, SAFEARRAY of bytes (VT_ARRAY|VT_UI1),
a DOMDocument object, or any object that supports IStream,
ISequentialStream, or IPersistStream. See Remarks for more information.
'===============================================================================
================='
if .nodeType is equal to: then .NodeName returns:
'===============================================================================
================='
NODE_ATTRIBUTE name of the attribute.
NODE_CDATA_SECTION literal string "#cdata-s
ection".
NODE_COMMENT literal string "#comment
".
NODE_DOCUMENT literal string "#documen
t".
NODE_DOCUMENT_TYPE name of the document typ
e; for example, xxx in <!DOCTYPE xxx ...>.
NODE_DOCUMENT_FRAGMENT literal string "#document-fragme
nt".
NODE_ELEMENT name of the XML tag, wit
h any namespace prefix included if present.
NODE_ENTITY name of the enti
ty.
NODE_ENTITY_REFERENCE name of the entity referenced. N
ote that the name does not include the leading ampersand or the trailing semicol
on. The name includes the namespace if one is present.
NODE_NOTATION name of the notation.
NODE_PROCESSING_INSTRUCTION target; the first token followin
g the <? characters.
NODE_TEXT literal string "
#text".
'===============================================================================
================='
'===============================================================================
================='
if .nodeType is equal to: then .nextSibling/.previousSibling retur
ns:
'===============================================================================
================='
NODE_ATTRIBUTE Null; these node types d
o not appear as children of any other nodes.
NODE_DOCUMENT
NODE_DOCUMENT_FRAGMENT
------
NODE_CDATA_SECTION node immediately followi
ng this node in the list of children of this node's parent.
NODE_COMMENT If no such node exists,
returns Null.
NODE_DOCUMENT_TYPE
NODE_ELEMENT
NODE_ENTITY
NODE_ENTITY_REFERENCE
NODE_NOTATION
NODE_PROCESSING_INSTRUCTION
NODE_TEXT
'===============================================================================
================='
'===============================================================================
================='
if .nodeType is equal to: then .firstChild/.lastChild returns:
'===============================================================================
================='
NODE_ATTRIBUTE the first child node. If there a
re no children, returns Null
NODE_DOCUMENT
NODE_DOCUMENT_FRAGMENT
NODE_DOCUMENT_TYPE
NODE_ELEMENT
NODE_ENTITY
NODE_ENTITY_REFERENCE
------
NODE_CDATA_SECTION Null . These node types cannot h
ave children.
NODE_COMMENT
NODE_NOTATION
NODE_PROCESSING_INSTRUCTION
NODE_TEXT
'===============================================================================
================='
'===============================================================================
================='
if .nodeType is equal to: then .childNodes returns:
'===============================================================================
================='
NODE_ATTRIBUTE IXMLDOMNodeList that contains a
list of all child nodes for the specified node.
NODE_DOCUMENT
NODE_DOCUMENT_FRAGMENT
NODE_ELEMENT
NODE_ENTITY
NODE_ENTITY_REFERENCE
-------
NODE_CDATA_SECTION IXMLDOMNodeList with a length of
0. These node types cannot have children.
NODE_COMMENT
NODE_NOTATION
NODE_PROCESSING_INSTRUCTION
NODE_TEXT
-------
NODE_DOCUMENT_TYPE IXMLDOMNodeList that contains a
list of all child nodes for the IXMLDOMDocumentType node.
The node list fo
r the document type node can contain entities and notations.
'===============================================================================
================='
Note that the white space within the CDATA node is preserved.
This value depends on the value of the nodeType property.
'===============================================================================
================='
if .nodeType is equal to: then .text returns:
'===============================================================================
================='
NODE_ATTRIBUTE Returns a string
representing the value of the node. This is the **concatenated** text of all su
bnodes with entities expanded.
NODE_DOCUMENT
NODE_ENTITY
---------
NODE_CDATA_SECTION text contained i
n the node, which is the same as the nodeValue property.
NODE_COMMENT
NODE_PROCESSING_INSTRUCTION
NODE_TEXT
---------
NODE_DOCUMENT_TYPE Returns the empt
y string (""). These node types do not have associated text.
NODE_NOTATION
---------
NODE_DOCUMENT_FRAGMENT Returns the text compris
ed of the concatenation of all descendant nodes.
---------
NODE_ELEMENT Contains a strin
g that represents the element content.
This will also include the text content from all child elements,
**concatenated** in document order. For example, consider the following XML.
'===============================================================================
================='
.text returns String. The property is read/write.
** When concatenated**, the text represents the contents of **text** or **CDATA*
* nodes.
All concatenated text nodes **are normalized** according to xml:space attributes
and the value of the preserveWhiteSpace switch.
Concatenated CDATA text is not normalized. (Child nodes that contain NODE_COMMEN
T and NODE_PROCESSING_INSTRUCTION nodes are not concatenated.)
.text trims the whitespace on the edges of the result, and "normalizes" \r\n =>
\n, but otherwise just concatenates text.
Retrieves and sets the string representing the text contents of this node or the
concatenated text representing this node and its descendants.
For more precise control over text manipulation in an XML document, use the lowe
r-level .nodeValue property,
which returns the raw text associated with a NODE_TEXT node.
'===============================================================================
================='
if .nodeType is equal to: then .nodeValue returns:
'===============================================================================
================='
NODE_ATTRIBUTE string representing the value of
the attribute. For attributes with subnodes, this is the concatenated text of a
ll subnodes with entities expanded. Setting this value deletes all children of t
he node and replaces them with a single text node containing the value written.
NODE_CDATA_SECTION string representing the text sto
red in the CDATA section.
NODE_COMMENT content of the comment, exclusiv
e of the comment's start and end sequence.
-----
NODE_DOCUMENT Null Note: that attempting to se
t the value of nodes of these types generates an error.
NODE_DOCUMENT_TYPE
NODE_DOCUMENT_FRAGMENT
NODE_ELEMENT
NODE_ENTITY
NODE_ENTITY_REFERENCE
NODE_NOTATION
----------
NODE_PROCESSING_INSTRUCTION content of the processing instruction, e
xcluding the target. (The target appears in the nodeName property.)
NODE_TEXT string representing the
text stored in the text node.
'===============================================================================
================='
The IXMLDOMNodeType enumeration defines the following valid values.
.nodeType/.nodeTypeString
NODE_ELEMENT (1) Contains: Element, Text,
Comment, ProcessingInstruction, CDATASection, EntityReference
Child of
: Document, DocumentFragment, EntityReference, Element.
NODE_ATTRIBUTE (2) Contains: Text and Entit
yReference
"attribute" Child of: none (
it is not considered a child node of an Element)
NODE_TEXT (3) text content of a tag
"text" Contains: none
Child of
: Attribute, DocumentFragment, Element, EntityReference
NODE_CDATA_SECTION (4) CDATA section in the XML source
"cdatasection" CDATA sections are used
to escape blocks of text that would otherwise be recognized as markup.
Contains
: none
Child of
: DocumentFragment, EntityReference, Element nodes.
NODE_ENTITY_REFERENCE (5) reference to an entity in the XM
L document
"entityreference" This applies to all enti
ties, including character entity references.
Contains
: Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference.
Child of
: Attribute, DocumentFragment, Element, EntityReference
NODE_ENTITY (6) expanded entity
"entity" Contains: child
nodes, that represent the expanded entity (for ex, Text and EntityReference).
Child of
: DocumentType
NODE_PROCESSING_INSTRUCTION (7) processing instruction from the XML docu
ment
"processinginstruction" Contains: none
Child of
: Document, DocumentFragment, Element, and EntityReference nodes.
NODE_COMMENT (8) comment in the XML docum
ent
"comment" Contains: none
Child of
: Document, DocumentFragment, Element, and EntityReference nodes.
NODE_DOCUMENT (9) document object, that as
the root of the document tree, provides access to the entire XML document
"document" It is created us
ing the progID "Microsoft.XMLDOM" or through a data island using <XML> or <SCRIP
T LANGUAGE=XML>.
Contains
: Element (maximum of one), ProcessingInstruction, Comment, and DocumentType.
Child of
: none
NODE_DOCUMENT_TYPE (10) document type declaration, indic
ated by the <!DOCTYPE> tag
"documenttype" Contains: Notation, Enti
ty.
Child of
: Document
NODE_DOCUMENT_FRAGMENT (11) document fragment. The DocumentFragment
node associates a node or subtree with a document
"documentfragment" without actually being
contained within the document.
Contains
: Element, ProcessingInstruction, Comment, Text, CDATASection, and EntityReferen
ce.
Child of
: none
NODE_NOTATION (12) notation in the document
type declaration
"notation" Contains: none
Child of
: DocumentType
objXmlDoc.LoadXML("<XmlStorage></XmlStorage>") ' load from text
rc = objXmlDoc.Load(mstrXmlFilePath) ' load from file
, true if succesfull
objXmlDoc.Save mstrXmlFilePath
objXmlDoc.Create
objXmlDoc.Create
node.getAttribute("AttributeName")
node.
createElement("ElementName")
{both}.SelectNodes(strXPath) ' DOMDocument an
d IXMLDOMElement
{both}.selectSingleNode(strXPath)
'================================================================='
' .open() - get xml from url
'================================================================='
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
xmlhttp.open("GET","http://localhost/books.xml", false);
xmlhttp.send(); ' xmlhttp.send(strBody);
var book = xmlhttp.responseXML.selectSingleNode("//book[@id='bk101']");
WScript.Echo(book.xml);
'============================================================='
********************************************************************************
********************************************************************************
*********
X P a t h
********************************************************************************
********************************************************************************
*********
/ Child operator; selects immediate children of the left-side coll
ection.
When this path operator appears at the start of the pattern, it
indicates
that children should be selected from the root node (regardless
of context)
// Recursive descent; searches for the specified element at any dep
th.
When this path operator appears at the start of the pattern,
it indicates recursive descent from the root node.
//E equal-to /descendant::E
descendant:: - its a
( ) Groups operations to explicitly establish precedence.
[ ] Applies a filter pattern. KOOL - select nodes if filter returns true
. filter has current context.
[ ] Subscript operator; used for indexing within a collection.
: namespace separator
::
{} ( HTML), XSLT
The filter pattern operators ([]) have a higher precedence than
the path operators (/ and //).
For example, the expression //comment()[3] selects all comments
with an index equal to 3 relative to the comment's
parent anywhere in the document. This differs from the expressio
n (//comment())[3], which selects the third
comment from the set of all comments relative to the parent. The
first expression can return more than one comment,
while the latter can return only one comment.
/E1/E2 ' absolu
te path, from the root node, (regardless of context)
//E
' relative path
//E1|//E2 ' matche
s element E1 or E2
//E[2] ' 2nd el
ement. XPath counts indexes starting from 1. getElementByName counts from 0
//E/*[2] ' first
child element. xpath counts indexes starting from 1. getElementByName counts fro
m 0
/*
' root node
/*/* ' all no
des under the root
*
matches any element node
@*
matches any attribute node
node() matches
any node of any kind
.
' self
./@A ' attrib
ute of current node. equal to @A
./E
' child element E of current node. equal to E
.//E ' All <E
> elements one or more levels deep in the current context.
' Note that this situation is essentially the only one in which the period notat
ion is required.
..
' parent
//E/.. ' parent
of element E
//E[E2] ' elemen
t E which has child element E2
//E[E1 and E2] ' element E whic
h has children elements E1 and E2
//E/@A ' attrib
ute A of element E
//E/@* ' all at
ributes of element E
//E[@A] ' elemen
t E which has attribute A
//E[@A='tt'] ' element E whic
h has attribute A equal to 'tt'
//E[@A='tt' or @A='gg'] ' element E which has at
tribute A equal to 'tt' or 'gg'
//E[contains(@A,'tt')] ' element E which has at
tribute A which value contains 'tt'
//E[matches(@A,'r')] ' element E which has at
tribute A which value matches regexp 'r'
//E[starts-with(@A,'1')] ' element E which has at
tribute A which value starts with '1'
//E[ends-with(@A,'1')] ' element E which has at
tribute A which value ends with '1'
//E[starts-with(.,'A')] ' element E which text v
alue starts with 'A'
//*/@A ' attrib
ute A of any element
//E[text()='some value'] ' Element E
//E[E1[position()=1]="Bob"] ' Returns element E whic
h has child E1 at pisition 1 whith text "Bob"
//div[div[@id='addresses_list']]
text() text nod
e. can be used as other nodes
/div//text() all text nodes u
nder the div
/div//text()[not(parent::p)] all text nodes under the div EXC
LUDING ones which have parent p
/a/b/c/. == /a/b/c
XPath.
---------------------------------------------------------
ancestor:: .
ancestor-or-self:: .
attribute:: .
child:: .
descendant:: .
descendant-or-self:: .
following:: ,
following-sibling:: ,
namespace:: , (
parent:: .
preceding::
preceding-sibling:: ,
self:: .
, :
attribute:: @
child::
descendant:: .//
parent:: ..
self:: .
:
============================================================
node() node-set .
text() string
current() node-set
,
.
position() number
last() number
count(node-set) number node
name(node-set?) string
namespace-uri(node-set?) string url
local-name(node-set?) string ,
id(object) node-set
------------------
string(object?) string
concat(string, string, string*) string
string-length(string?) number .
contains(string, string) boolean ,
substring(string, number, number?) string
substring-before(string, string) string ,
substring-after(string, string) string ,
starts-with(string, string) boolean
ends-with(string, string) boolean
normalize-space(string?) string
translate(string, string, string) string ,
. translate(bar, abc, ABC)
----------------------
or
and
=
< (<)
> (>)
<= (<=)
>= (>=)
boolean(object) boolean ;
true() boolean .
false() boolean .
not(boolean) boolean , .
------------------------------------------
+
?
*
div ( !)
mod
number(object?) number .
sum(node-set) number ,
floor(number) number , , .
ceiling(number) number , , .
round(number) number .
********************************************************************************
********************************************************************************
*********
C S S
http://www.w3schools.com/cssref/default.asp
********************************************************************************
********************************************************************************
*********
Selector Example
Example description
CSS
------------------------------------------------------------------------
--------------------------------------------------------------------------------
-------------
.class .intro
Selects all elements with class="intro"
1
#id #firstname
Selects the element with id="firstname"
1
* *
Selects all elements
2
element p
Selects all <p> elements
1
element,element div,p
Selects all <div> elements and all <p> elements
1
element element div p
Selects all <p> elements inside <div> elements
1
element>element div>p
Selects all <p> elements where the parent is a <div> element
2
element+element div+p
Selects all <p> elements that are placed immediately after <div> elements
2
[attribute] [target]
Selects all elements with a target attribute
2
[attribute=value] [target=_blank]
Selects all elements with target="_blank"
2
[attribute~=value] [title~=flower]
Selects all elements with a title attribute containing the word "flower"
2
[attribute|=value] [lang|=en]
Selects all elements with a lang attribute value starting with "en"
2
E[attr1][attr2]
Selects all elements with attr1 AND attr2
:link a:link
Selects all unvisited links
1
:visited a:visited
Selects all visited links
1
:active a:active
Selects the active link
1
:hover a:hover
Selects links on mouse over
1
:focus input:focus
Selects the input element which has focus
2
:first-letter p:first-letter
Selects the first letter of every <p> element
1
:first-line p:first-line
Selects the first line of every <p> element
1
:first-child p:first-child
Selects every <p> element that is the first child of its parent
2
:before p:before
Insert content before the content of every <p> element
2
:after p:after
Insert content after every <p> element
2
:lang(language) p:lang(it)
Selects every <p> element with a lang attribute value starting with "it"
2
element1~element2 p~ul
Selects every <ul> element that are preceded by a <p> element
3
[attribute^=value] a[src^="https"]
Selects every <a> element whose src attribute value begins with "https"
3
[attribute$=value] a[src$=".pdf"]
Selects every <a> element whose src attribute value ends with ".pdf"
3
[attribute*=value] a[src*="w3schools"]
Selects every <a> element whose src attribute value contains the substring "w3sc
hools" 3
:first-of-type p:first-of-type
Selects every <p> element that is the first <p> element of its parent
3
:last-of-type p:last-of-type
Selects every <p> element that is the last <p> element of its parent
3
:only-of-type p:only-of-type
Selects every <p> element that is the only <p> element of its parent
3
:only-child p:only-child
Selects every <p> element that is the only child of its parent
3
:nth-child(n) p:nth-child(2)
Selects every <p> element that is the second child of its parent
3
:nth-last-child(n) p:nth-last-child(2)
Selects every <p> element that is the second child of its parent, counting from
the last child 3
:nth-of-type(n) p:nth-of-type(2)
Selects every <p> element that is the second <p> element of its parent
3
:nth-last-of-type(n) p:nth-last-of-type(2) Selects
every <p> element that is the second <p> element of its parent, counting from th
e last child 3
:last-child p:last-child
Selects every <p> element that is the last child of its parent
3
:root :root
Selects the document's root element
3
:empty p:empty
Selects every <p> element that has no children (including text nodes)
3
:target #news:target
Selects the current active #news element (clicked on a URL containing that ancho
r name) 3
:enabled input:enabled
Selects every enabled <input> element
3
:disabled input:disabled
Selects every disabled <input> element
3
:checked input:checked
Selects every checked <input> element
3
:not(selector) :not(p)
Selects every element that is not a <p> element
3
::selection ::selection
Selects the portion of an element that is selected by a user
3
===== Sizzle (not CSS) ======
:contains() p:contains('theText')
Selects p which contains text "theText"
--------------------------
style precedence: http://www.vanseodesign.com/css/css-specificity-inherita
nce-cascaade/
--------------------------
Specificity(precedence) is calculated by counting various components of your css
and expressing them in a form (a,b,c,d).
Inline Style: a = 1 (1,0,0,0)
Id: b = 1 (0
,1,0,0)
Class, Pseudo class, Attribute: c = 1 (0,0,1,0)
Element, Pseudo Element: d = 1 (0,0,0,1)
An id is more specific than a class is more specific than an element.
You calculate specificity by counting each of the above and adding 1 to
either a,b,c, or d.
It's also important to note that 0,0,1,0 is more specific than 0,0,0,15.
Let's look at some examples to make the calculation clearer.
priority (
p : 1 element
(0,0,0,1) 0 (low)
div : 1 element
(0,0,0,1) 0
div p : 2 elements
(0,0,0,2) 1
#sidebar : 1 id
(0,1,0,0) 2
div#sidebar : 1 element, 1 id
(0,1,0,1) 3
div#sidebar p : 2 elements, 1 id
(0,1,0,2) 4
div#sidebar p.bio : 2 elements, 1 class, 1 id (0,1,1,2)
5 (high)
If two rules has equal priority, the one declared last (in css-file) win
s. CSS embedded in the html
always come after external stylesheets regardless of the order in the ht
m
Your styles can be overrided by user styles (unless they set their rules
to be !important: {font-size: 14px !important}
Your styles will override the browser defaults
Browser defaults do exist and is often what leads to cross brows
er issues.
Using a reset file like Eric Meyer's CSS Reset or Yahoo's YUI Reset
CSS helps
take the default styles out of the equation.
--------------------------
Inheritance http://www.vanseodesign.com/css/css-specificity-inherita
nce-cascaade/
--------------------------
1. Not all css properties are inherited (by default).
For example margins and paddings are non-inherited properties.
If you set a margin or padding on a div, the paragraphs
inside that div do not inherit
the margin and padding you set on the div. The paragraph
will use the default browser
margin and padding until you declare otherwise.
2. You can explicitly set a property to inherit styles from it's parent co
ntainer, though.
For example you could declare
p {margin: inherit; padding: inherit}
and your paragraph would then inherit both from it's containing el
ement.
Overview from the CSS Level 2 selectors spec with added XPath equivalents
CSS Pattern XPath equivalent
Meaning
* *
Matches any element.
E E
Matches any E element (i.e., an element of type E).
E F E//F
Matches any F element that is a descendant of an E element.
E > F E/F
Matches any F element that is a child of an element E.
E + F E/following-sibling::*[1]/self::F
Matches any F element immediately preceded by an element E.
E#myid E[@id = "myid"]
Matches any E element ID equal to "myid".
E[foo] E[@foo]
Matches any E element with the "foo" attribute set (whatever the value).
E[foo = "warning"] E[@foo = "warning"]
Matches any E element whose "foo" attribute value is exactly equal to "warning".
E:first-child *[1]/self::E
Matches element E when E is the first child of its parent.
E:lang(c) E[@xml:lang = "c" or
Matches element of type E if it is in (human) language c
starts-with(
(the document language specifies how language is determined).
@xml:lang,"c-")]
E[foo~="warning"] E[contains(
Matches any E element whose "foo" attribute value is a list
concat(" ",@foo," "),
of space-separated values, one of which is exactly equal to "warning".
" warning ")]
E.warning E[contains(
HTML only. The same as DIV[class~="warning"].
concat(" ",@class," "),
" warning ")]
E[lang|="en"] E[@lang = "en" or
Matches any E element whose "lang" attribute has a hyphen-separated
starts-with(@lang, "en-"
)] list of values beginning (from the left) with "en".
==============================================================
XSLT http://msdn.microsoft.com/ru-ru/library/ms256181(v=vs.110).aspx
msdn.microsoft.com msxsl.exe, .
, document
msxsl document1.xml document1.xsl
==============================================================
copy-of returns a copy of the element - all content of element "as is"-w
ith subnodes
value-of returns the string value of an element - concatenated text of al
l subnodes
document(object, node-set?) http://msdn.microsoft.com/ru-ru/library/ms256465(v=
vs.110).aspx
parse-xml() - XSLT3
<html>
<head>
<script>
function loadXMLDoc(filename)
{
if (window.ActiveXObject)
{
xhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
else
{
xhttp = new XMLHttpRequest();
}
xhttp.open("GET", filename, false);
try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11
xhttp.send("");
return xhttp.responseXML;
}
function displayResult()
{
xml = loadXMLDoc("cdcatalog.xml");
xsl = loadXMLDoc("cdcatalog.xsl");
// code for IE
if (window.ActiveXObject || xhttp.responseType == "msxml-document")
{
ex = xml.transformNode(xsl);
document.getElementById("example").innerHTML = ex;
}
// code for Chrome, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml, document);
document.getElementById("example").appendChild(resultDocument);
}
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
</html>
---------------------------------------------------------
---------------------------------------------------------
---------------------------------------------------------
---------------------------------------------------------
function display(dname, compt) {
document.getElementById(dname+"Table").innerHTML="";
// IE
if (window.ActiveXObject) {
xml = new ActiveXObject("MSXML2.DOMDocument.3.0");
xml.async = false;
xml.load(dname+".xml");
xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument.3.0");
xsl.async = false;
xsl.load(dname+".xsl");
docCache = new ActiveXObject("MSXML2.XSLTemplate.3.0");
docCache.stylesheet = xsl;
docProcessor = docCache.createProcessor();
docProcessor.input = xml;
docProcessor.addParameter("competitor", compt);
docProcessor.transform();
document.getElementById(dname+"Table").innerHTML = docProcessor.output;
}
// Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument) {
xml=loadXMLDoc(dname+".xml");
xsl=loadXMLDoc(dname+".xsl");
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
xsltProcessor.setParameter(null, "competitor", compt);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById(dname+"Table").appendChild(resultDocument);
}
---------------------------------------------------------
---------------------------------------------------------
---------------------------------------------------------
---------------------------------------------------------
[======================================================
???? replacement ???? for
parse-xml() from XSLT 3.0
=======================================================
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:my="my:my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="summary/text()">
<xsl:copy-of select="my:parse(.)/*/*"/>
</xsl:template>
<msxsl:script language="c#" implements-prefix="my">
public XmlDocument parse(string text)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<t>"+text+"</t>");
return doc;
}
</msxsl:script>
</xsl:stylesheet>
==============================================================]