You can stick with your method. With a slight modification, it works.
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x/\content/\style in {%
0/a/draw,
1/b/{draw=red},
2/c/{circle,draw=blue},
3/d/draw
}{
\edef\x{\noexpand\node[\style] at (\x,0) {\content}}\x;
}
\end{tikzpicture}
\end{document}
And PolGab's solution is:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[0/.style=draw,1/.style={draw=red},
2/.style={circle,draw=blue},3/.style=draw]
\foreach \x/\content in {0/a, 1/b, 2/c, 3/d}{
\node[\x] at (\x,0) {\content};
}
\end{tikzpicture}
\end{document}
EDIT (2012/07/22)
Expanding on Andrew Stacey's solution, here is another one. Using +
to list the keys eliminates the need for braces. The code can be generalized to take any symbol in place of +
.
\documentclass{article}
\usepackage{tikz}
\makeatletter
\def\replaceplus#1{\xreplaceplus#1+\@nil}
\def\xreplaceplus#1+#2\@nil{%
\ifcat$\detokenize{#2}$\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi
{\unexpanded{#1}}{\xreplaceplus#1,#2\@nil}%
}
\newcommand*\tikzexpanded[2]{%
\begingroup
\def\reserved@a##1#1##2##3\@nil{%
\ifx\@nnil##2\def\x{#2}\else\edef\x{##2{#2}}\fi
}%
\reserved@a
xx{\@iden}x0{\unexpanded}x1{\unexpanded\expandafter}%
x2{\unexpanded\expandafter\expandafter\expandafter}#1{\@nnil}\@nil
\edef\x{\expandafter\replaceplus\expandafter{\x}}%
\edef\x{\endgroup\noexpand\tikzset{\unexpanded\expandafter{\x}}}\x
}
\tikzset{%
use style/.code={\tikzset{#1}},
use style expanded/.code={\tikzexpanded{xx}{#1}},
use style expand once/.code={\tikzexpanded{x1}{#1}},
use style expand twice/.code={\tikzexpanded{x2}{#1}}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\path \foreach \x/\content/\style in{%
0/a/draw,
1/b/draw + red,
2/c/circle + draw=blue,
3/d/draw
}{
node[use style expand once=\style] at (\x,0) {\content}
};
\end{tikzpicture}
\end{document}
red drawing/.style={red, draw}
and use this style in your loop.\tikzset{somekey/.style={draw, red}}
and insertsomekey
instead of the comma-list.