A stylesheet_item object to be inserted. As stylesheet_item is a base class, the passed object will actually be one of the
following types, stylesheet_rule, stylesheet_import, or stylesheet_comment.
pos
A stylesheet iterator which points to the position where the stylesheet
item is to be inserted.
This operation is used to insert stylesheet items from the called stylesheet. The most common stylesheet item you'll insert into a stylesheet is a stylesheet_rule.
In the first variety, the stylesheet item is inserted at the end of the stylesheet. The 2nd variety allows you to specify where the stylesheet item
is inserted.
Complexity
Logarithmic
Examples
1st Variety
#include "xhtml_doc.h"
#include "xport_brochure.h"
#include <iostream>
int main(int argc, char* argv[])
{
using namespace Xport;
stylesheet ss;
ss.insert(stylesheet_comment("Sample stylesheet"));
// add a rule for h1 elements
stylesheet::iterator it = ss.insert(stylesheet_rule("h1"));
it->insert(declaration(text_align, "center"));
it->insert(declaration(css::color, "red"));
// add a rule for p elements
it = ss.insert(stylesheet_rule("p"));
it->insert(declaration(margin_left, "10px"));
it->insert(declaration(font_size, "10pt"));
// write the stylesheet to cout
stylesheet_formatter fmtr(std::cout);
ss.write(fmtr);
}
2nd Variety
#include "xhtml_doc.h"
#include "xport_brochure.h"
#include <iostream>
#include <algorithm>
struct compare_selector_functor
{
compare_selector_functor(const std::string& s) : sel(s) {}
bool operator() (const Xport::stylesheet_item& item) { return item.selector() == sel; }
std::string sel;
};
int main(int argc, char* argv[])
{
using namespace Xport;
document doc(root_doc);
stylesheet ss;
xport_brochure broch;
broch.create(doc, ss);
// write xport brochure stylesheet to cout
stylesheet_formatter fmtr(std::cout);
ss.write(fmtr);
// now insert a new pre rule before the 'p' rule
stylesheet::iterator it = std::find_if(ss.begin(), ss.end(), compare_selector_functor("p"));
if (it != ss.end()) {
it = ss.insert(it, stylesheet_rule("pre"));
it->insert(declaration(background_color, "grey"));
}
std::cout << "\n\nStylesheet after inserting pre rule.\n\n";
ss.write(fmtr);
}
Datasoft Solutions is proud to present their landmark product, Work Time Studio. Utilizing the tree container library, Work Time Studio provides
unparalleled features in personal time, project and task management
software. If you're looking for a way to increase your productivity,
visit Work Time Studio's product website, and start being more productive
today.