Edit 01 Feb 2012
One idea is to make things expandable. Here is a first attempt.
\tikzset{my style/.style = {minimum width = 2cm,inner xsep=3cm}}
\def\pgfkeysmarkkey#1{%
\expandafter\def\csname pgfkeysvaluefromstyle@ii@#1\endcsname
##1,##2#1##3=##4,##5\pgfeov{##4}}
\def\pgfkeysvaluefromstyle#1{%
\expandafter\expandafter\expandafter\pgfkeysvaluefromstyle@i
\csname pgfk@/tikz/#1/.@cmd\endcsname\pgfeov}
\def\pgfkeysvaluefromstyle@i\pgfkeysalso#1#2{%
\csname pgfkeysvaluefromstyle@ii@#2\endcsname,#1,\pgfeov}
\pgfkeysmarkkey{minimum width}
\pgfkeysvaluefromstyle{my style}{minimum width}
Some comments. When defining a style, the .style handler defines a macro \pgfk@<long path to the key>/.@cmd where <long path to the key> is /tikz/my style for a style defined by \tikzset{my style/.style = ...}.
This macro takes one argument delimited by \pgfeov. In this macro, the whole definition of the style is stored as an argument given to \pgfkeysalso. So if one defines my style with \tikzset{my style/.style = {minimum width = 2cm, inner xsep = 3cm}}, the macro \pgfk@/tikz/my style/.@cmd (called with \pgfk@/tikz/my style/.@cmd<arg>\pgfeov where <arg> is a possibly empty argument) will expand to \pgfkeysalso{minimum width = 2cm, inner xsep = 3cm}.
The idea is to get rid of \pgfkeysalso to get the key = val list of the style and the parse the key = val list to get the value we are looking for.
To make it expandable, I do not see another solution than to "mark" the key we are looking for.
So here is the working example.
\documentclass{article}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\makeatletter
\def\pgfkeysmarkkey#1{%
\expandafter\def\csname pgfkeysvaluefromstyle@ii@#1\endcsname
##1,##2#1##3=##4,##5\pgfeov{##4}}
\def\pgfkeysvaluefromstyle#1{%
\expandafter\expandafter\expandafter\pgfkeysvaluefromstyle@i
\csname pgfk@/tikz/#1/.@cmd\endcsname\pgfeov}
\def\pgfkeysvaluefromstyle@i\pgfkeysalso#1#2{%
\csname pgfkeysvaluefromstyle@ii@#2\endcsname,#1,\pgfeov}
\makeatother
\tikzset{mystyle/.style={outer xsep=10pt, outer ysep=10pt}}
\pgfkeysmarkkey{outer ysep}
\titlespacing*{\section}{\pgfkeysvaluefromstyle{mystyle}{outer ysep}}{0pt}{0pt}
\begin{document}
\section{Section}
\end{document}
Here is what I suggest (I choose to work with minimal width rather than outer xsep but I hope it is clear it is the same). It may not be the best approach but, right now, I do not have any other ideas.
The idea is to use the key handler .forward to so that any call to mystyle will trigger the key /tikz/save my style minimum width that will exec two things:
- set (locally to the group) the key
/tikz/my style minimum width to the value of minimum width defined with the style mystyle.
- set (globally) the macro
\mystyleminimumwidthvalue so that it expands to the value of minimum width defined with the style mystyle.
When the style is used once say, in a \draw command, the options are set locally so it is not possible to access the value saved outside of the \draw command (see last \node in the first tikzpicture in the example below). (Note that the trick with \edef\x is required because for some reason \pgfmathparse, called by the key minimum width, does not like \pgfkeysvalueof as an argument [I may be wrong here]).

\documentclass{standalone}
\usepackage{tikz}
\tikzset{%
mystyle/.style = {%
minimum width = 2cm},
mystyle/.forward to = /tikz/save my style minimum width,
save my style minimum width/.code = {%
\pgfkeyssetvalue{/tikz/my style minimum width}{%
\pgfkeysvalueof{/pgf/minimum width}}%
\xdef\mystyleminimumwidthvalue{%
\pgfkeysvalueof{/pgf/minimum width}}},
my style minimum width/.initial = \pgfkeysvalueof{/pgf/minimum width}}
\begin{document}
\begin{tikzpicture}
\node[draw,mystyle] at (0,0) {\pgfkeysvalueof{/pgf/minimum width}};
\node[draw,red,minimum width = 5cm] at (2,0)
{\pgfkeysvalueof{/pgf/minimum width}};
\begingroup
\edef\x{%
\endgroup
\noexpand\node[draw,blue,minimum width = \pgfkeysvalueof{/tikz/my style
minimum width}] at (4,0) {\pgfkeysvalueof{/tikz/my style
minimum width}};}
\x
\end{tikzpicture}
\begin{tikzpicture}[mystyle]
\begingroup
\edef\x{%
\endgroup
\noexpand\node[draw,blue,minimum width = \pgfkeysvalueof{/tikz/my style
minimum width}] at (4,0) {\pgfkeysvalueof{/tikz/my style
minimum width}};}
\x
\end{tikzpicture}
\end{document}
\pgfkeysvalueof{/peek/a style/a key}so it would be possible to access the value ofa keyredefined in another style. – cjorssen Feb 02 '12 at 12:27\pgfkeysvaluefromstyleshows the same problems than my initial attempt if applied to the MWE (pdflatex hangs) :-( – Daniel Feb 03 '12 at 10:24\titlespacing*, and the command here does not actually expand into a length (not expandable, remember). The reason your attempt with\Xoutersepworked is that you did the non-expandable part before calling\titlespacing*, so the only thing there ended up being a macro with the number in it. The same thing will work if you use the.peek//peek/outer xsepkey combination rather than\pgfkeysvaluefromstyle(BTW:\pgfkeysvalueofis expandable). – Ryan Reich Feb 03 '12 at 17:43\foreachloop). – Ryan Reich Feb 03 '12 at 17:54/peek/outer xsepis the necessary grouping to not pollute thepeekdirectory; putting\titlespacing*into the same group also pops its effects at the end of the group. So in this particular case I have to go the route via some global\outersepmacro that is set inside the group and then used outside). However, I really do like the general elegance of your approach. – Daniel Feb 03 '12 at 22:53